Code_Saturne
CFD tool
Functions
ecs_mem.c File Reference
#include "ecs_def.h"
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "ecs_mem.h"
#include "ecs_mem_usage.h"

Functions

void ecs_mem_init (const char *log_file_name)
 Initialize memory handling. More...
 
void ecs_mem_end (void)
 End memory handling. More...
 
int ecs_mem_initialized (void)
 Indicates if ecs_mem_...() functions are initialized. More...
 
void * ecs_mem_malloc (size_t ni, size_t size, const char *var_name, const char *file_name, int line_num)
 Allocate memory for ni elements of size bytes. More...
 
void * ecs_mem_realloc (void *ptr, size_t ni, size_t size, const char *var_name, const char *file_name, int line_num)
 Reallocate memory for ni elements of size bytes. More...
 
void * ecs_mem_free (void *ptr, const char *var_name, const char *file_name, int line_num)
 Free allocated memory. More...
 
size_t ecs_mem_size_current (void)
 Return current theoretical dynamic memory allocated. More...
 
size_t ecs_mem_size_max (void)
 Return maximum theoretical dynamic memory allocated. More...
 

Function Documentation

◆ ecs_mem_end()

void ecs_mem_end ( void  )

End memory handling.

This function should be called after all other ecs_mem_...() functions. In case of memory allocation logging, it writes final information to the log file and closes is.

◆ ecs_mem_free()

void* ecs_mem_free ( void *  ptr,
const char *  var_name,
const char *  file_name,
int  line_num 
)

Free allocated memory.

This function calls free(), but adds tracing capabilities, and automatically calls the ecs_error() errorhandler if it fails to free the corresponding memory. In case of a NULL pointer argument, the function simply returns.

Parameters
[in]ptrpointer to previous memory location (if NULL, ecs_alloc() called).
[in]var_nameallocated variable name string
[in]file_namename of calling source file
[in]line_numline number in calling source file
Returns
NULL pointer.

◆ ecs_mem_init()

void ecs_mem_init ( const char *  log_file_name)

Initialize memory handling.

This function should be called before any other ecs_mem_...() function. To activate memory allocation logging, a logfile name should be given as an argument. The resulting file will be a regular, local file. If this file cannot be opened for some reason, logging is silently de-activated.

Parameters
log_file_namename of optional log_file (if NULL, no log).

◆ ecs_mem_initialized()

int ecs_mem_initialized ( void  )

Indicates if ecs_mem_...() functions are initialized.

Returns
1 if ecs_mem_init has been called, 0 otherwise.

◆ ecs_mem_malloc()

void* ecs_mem_malloc ( size_t  ni,
size_t  size,
const char *  var_name,
const char *  file_name,
int  line_num 
)

Allocate memory for ni elements of size bytes.

This function calls malloc(), but adds tracing capabilities, and automatically calls the ecs_error() errorhandler if it fails to allocate the required memory.

Parameters
[in]ninumber of elements.
[in]sizeelement size.
[in]var_nameallocated variable name string.
[in]file_namename of calling source file.
[in]line_numline number in calling source file.
Returns
pointer to allocated memory.

◆ ecs_mem_realloc()

void* ecs_mem_realloc ( void *  ptr,
size_t  ni,
size_t  size,
const char *  var_name,
const char *  file_name,
int  line_num 
)

Reallocate memory for ni elements of size bytes.

This function calls realloc(), but adds tracing capabilities, and automatically calls the ecs_error() errorhandler if it fails to allocate the required memory.

Parameters
[in]ptrpointer to previous memory location (if NULL, ecs_alloc() called).
[in]ninumber of elements.
[in]sizeelement size.
[in]var_nameallocated variable name string.
[in]file_namename of calling source file.
[in]line_numline number in calling source file.
Returns
pointer to reallocated memory.
Here is the call graph for this function:

◆ ecs_mem_size_current()

size_t ecs_mem_size_current ( void  )

Return current theoretical dynamic memory allocated.

Returns
current memory handled through ecs_mem_...() (in kB).

◆ ecs_mem_size_max()

size_t ecs_mem_size_max ( void  )

Return maximum theoretical dynamic memory allocated.

Returns
maximum memory handled through ecs_mem_...() (in kB).