GenSVM
Functions
gensvm_memory.c File Reference

Utility functions for memory allocation. More...

#include "gensvm_globals.h"
Include dependency graph for gensvm_memory.c:

Go to the source code of this file.

Functions

void * mycalloc (const char *file, int line, unsigned long size, size_t typesize)
 Wrapper for calloc() which warns when allocation fails. More...
 
void * mymalloc (const char *file, int line, unsigned long size)
 Wrapper for malloc() which warns when allocation fails. More...
 
void * myrealloc (const char *file, int line, unsigned long size, void *var)
 Wrapper for realloc() which warns when allocation fails. More...
 

Detailed Description

Utility functions for memory allocation.

Author
G.J.J. van den Burg
Date
2016-05-01

This file is part of GenSVM.

GenSVM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

GenSVM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GenSVM. If not, see http://www.gnu.org/licenses/.

Definition in file gensvm_memory.c.

Function Documentation

◆ mycalloc()

void* mycalloc ( const char *  file,
int  line,
unsigned long  size,
size_t  typesize 
)

Wrapper for calloc() which warns when allocation fails.

This is a wrapper function around calloc from <stdlib.h>. It tries to allocate the requested memory and checks if the memory was correctly allocated. If not, an error is printed using err(), which describes the file and linenumber and size failed to allocate. After this, the program exits. See also the defines in gensvm_memory.h.

Note
This function should not be used directly. Calloc() should be used.
Parameters
[in]filefilename used for error printing
[in]lineline number used for error printing
[in]sizethe size to allocate
[in]typesizethe size of the type to allocate
Returns
the pointer to the memory allocated

Definition at line 48 of file gensvm_memory.c.

◆ mymalloc()

void* mymalloc ( const char *  file,
int  line,
unsigned long  size 
)

Wrapper for malloc() which warns when allocation fails.

This is a wrapper function around malloc from <stdlib.h>. It tries to allocate the requested memory and checks if the memory was correctly allocated. If not, an error is printed using err(), which describes the file and linenumber and size failed to allocate. After this, the program exits. See also the defines in gensvm_memory.h.

Note
This function should not be used directly. Malloc() should be used.
Parameters
[in]filefilename used for error printing
[in]lineline number used for error printing
[in]sizethe size to allocate
Returns
the pointer to the memory allocated

Definition at line 81 of file gensvm_memory.c.

◆ myrealloc()

void* myrealloc ( const char *  file,
int  line,
unsigned long  size,
void *  var 
)

Wrapper for realloc() which warns when allocation fails.

This is a wrapper function around realloc from <stdlib.h>. It tries to reallocate the requested memory and checks if the memory was correctly reallocated. If not, an error is printed using err(), which describes the file and linenumber and size failed to reallocate. After this, the program exits. See also the defines in gensvm_memory.h.

Note
This function should not be used directly. Realloc() should be used.
Parameters
[in]filefilename used for error printing
[in]lineline number used for error printing
[in]sizethe size to allocate
[in]varthe pointer to the memory to reallocate
Returns
the pointer to the memory reallocated

Definition at line 113 of file gensvm_memory.c.