Mescal
Loading...
Searching...
No Matches
alloc.c File Reference

Allocation helpers. Please use the macros of alloc.h instead of these. More...

#include "alloc.h"

Functions

void multiple_free (void *p,...)
 Function to free memory using the free() function.
 
void check_null (const char *function, char *file, int line, int n,...)
 Do not use this function directly; instead, use the macro CHECK_NULL(), which includes the error's location in the source code in the message.
 

Detailed Description

Allocation helpers. Please use the macros of alloc.h instead of these.

Function Documentation

◆ check_null()

void check_null ( const char * function,
char * file,
int line,
int n,
... )

Do not use this function directly; instead, use the macro CHECK_NULL(), which includes the error's location in the source code in the message.

See also
CHECK_NULL()

◆ multiple_free()

void multiple_free ( void * p,
... )

Function to free memory using the free() function.

Calls free on a variable number of arguments. The last argument must be NULL.

Example of use:

int *p1, *p2, *p3;
MALLOC(p1, 10); // Allocates an array of 10 ints.
MALLOC(p2, 10);
MALLOC(p3, 10);
// ...
multiple_free(p1, p2, p3, NULL);
void multiple_free(void *p,...)
Function to free memory using the free() function.
Definition alloc.c:8
#define MALLOC(p, num_objects)
Macro for allocating memory using the malloc() function.
Definition alloc.h:53
Attention
This function is dangerous and should only be used if you know what you are doing! The pointers to be freed must not be NULL. In the example above, if p2 is NULL, p3 will not be freed, which can cause a memory leak.