GenSVM
Macros | Functions
gensvm_memory.h File Reference

Header file for gensvm_memory.c. More...

#include <stddef.h>
Include dependency graph for gensvm_memory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define Calloc(type, size)   mycalloc(__FILE__, __LINE__, size, sizeof(type))
 
#define Malloc(type, size)   mymalloc(__FILE__, __LINE__, (size)*sizeof(type))
 
#define Realloc(var, type, size)   myrealloc(__FILE__, __LINE__, (size)*sizeof(type), var)
 
#define Memset(var, type, size)   memset(var, 0, (size)*sizeof(type))
 

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

Header file for gensvm_memory.c.

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

Contains macro definitions for easy memory access.

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.h.

Macro Definition Documentation

◆ Calloc

#define Calloc (   type,
  size 
)    mycalloc(__FILE__, __LINE__, size, sizeof(type))

Wrapper macro for mycalloc(). This macro uses the FILE and LINE standard macros to fill in some of the arguments to mycalloc(). This macro should be used when writing code, not mycalloc().

Definition at line 40 of file gensvm_memory.h.

◆ Malloc

#define Malloc (   type,
  size 
)    mymalloc(__FILE__, __LINE__, (size)*sizeof(type))

Wrapper macro for mymalloc(). This macro uses the FILE and LINE standard macros to fill in some of the arguments to mymalloc(). This macro should be used when writing code, not mymalloc().

Definition at line 48 of file gensvm_memory.h.

◆ Memset

#define Memset (   var,
  type,
  size 
)    memset(var, 0, (size)*sizeof(type))

Wrapper macro for memset(). Since memset is only used to zero a matrix, this macro is defined.

Definition at line 61 of file gensvm_memory.h.

◆ Realloc

#define Realloc (   var,
  type,
  size 
)    myrealloc(__FILE__, __LINE__, (size)*sizeof(type), var)

Wrapper macro for myrealloc(). This macro uses the FILE and LINE standard macros to fill in some of the arguments to myrealloc(). This macro should be used when writing code, not myrealloc().

Definition at line 55 of file gensvm_memory.h.

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.