1.4.0
CCC
 
memory.cpp File Reference
#include "Basic/AStringable.hpp"
#include "Basic/String.hpp"
#include "Basic/Timer.hpp"
#include "Basic/Memory.hpp"
#include "Core/Keypair.hpp"
#include <string.h>

Functions

void time_start (void)
 
static void st_time_chunk_close (void)
 
void time_reset (void)
 
void time_chunk_add (const char *call_name)
 
void time_report (void)
 
static void st_mem_update (int size)
 
void memory_leak_reset (void)
 
static void st_memory_leak_add (const char *call_file, int call_line, size_t size, void *ptr)
 
static void st_memory_leak_delete (const char *call_file, unsigned int call_line, void *ptr)
 
void memory_leak_report (void)
 
void mem_debug_set (int flag)
 
void memory_leak_set (int flag)
 
void memory_status (const char *title)
 
static void st_mem_message (const char *call_file, unsigned int call_line, const char *format, int oper, int size)
 
char * mem_free_ (const char *call_file, unsigned int call_line, char *tab)
 
char * mem_alloc_ (const char *call_file, unsigned int call_line, int size, int flag_fatal)
 
char * mem_copy_ (const char *call_file, unsigned int call_line, char *tabin, int size, int flag_fatal)
 
char * mem_calloc_ (const char *call_file, unsigned int call_line, int size, int size_elem, int flag_fatal)
 
char * mem_realloc_ (const char *call_file, unsigned int call_line, char *tab, int size, int flag_fatal)
 
double ** mem_tab_free (double **tab, int nvar)
 
double ** mem_tab_alloc (int nvar, int size, int flag_fatal)
 

Variables

static int MEMORY_LEAK = 0
 
static int MEMORY_DEBUG = 0
 
static int MEMORY_TOTAL = 0
 
static int MEMORY_MAX = 0
 
static int MEMORY_MIN_PT = 1000000
 
static int NB_MEM_CHUNK = 0
 
static int NB_TIME_CHUNK = 0
 
static int TIME_FOCUS = -1
 
static hrc::time_point TIME_CURRENT = hrc::time_point()
 
static MemChunk ** MemLeak = NULL
 
static TimeChunk ** TimeStat = NULL
 

Function Documentation

◆ mem_alloc_()

char* mem_alloc_ ( const char *  call_file,
unsigned int  call_line,
int  size,
int  flag_fatal 
)

Core allocation routine

Returns
Pointer to the array to be allocated
Parameters
[in]call_fileName of the calling file
[in]call_lineLine in the calling file
[in]sizeNumber of bytes
[in]flag_fatalError status (1 = the program stops)

◆ mem_calloc_()

char* mem_calloc_ ( const char *  call_file,
unsigned int  call_line,
int  size,
int  size_elem,
int  flag_fatal 
)

Core allocation routine

Returns
Pointer to the array to be allocated
Parameters
[in]call_fileName of the calling file
[in]call_lineLine in the calling file
[in]sizeNumber of elements
[in]size_elemNumber of bytes per element
[in]flag_fatalError status (1 = the program stops)

◆ mem_copy_()

char* mem_copy_ ( const char *  call_file,
unsigned int  call_line,
char *  tabin,
int  size,
int  flag_fatal 
)

Core routine for allocating and copying

Returns
Pointer to the newly allocated (and copied) array
Parameters
[in]call_fileName of the calling file
[in]call_lineLine in the calling file
[in]tabinArray to be copied
[in]sizeNumber of bytes
[in]flag_fatalError status (1 = the program stops)

◆ mem_debug_set()

void mem_debug_set ( int  flag)

Set the status of the memory

Parameters
[in]flagActiviation flag

◆ mem_free_()

char* mem_free_ ( const char *  call_file,
unsigned int  call_line,
char *  tab 
)

Core deallocation

Returns
Pointer to the freed array
Parameters
[in]call_fileName of the calling file
[in]call_lineLine in the calling file
[in]tabArray to be freed

◆ mem_realloc_()

char* mem_realloc_ ( const char *  call_file,
unsigned int  call_line,
char *  tab,
int  size,
int  flag_fatal 
)

Core re-allocation routine

Returns
Pointer to the array to be re_allocated
Parameters
[in]call_fileName of the calling file
[in]call_lineLine in the calling file
[in]tabArray to be reallocated
[in]sizeNew number of bytes
[in]flag_fatalError status (1 = the program stops)

◆ mem_tab_alloc()

double** mem_tab_alloc ( int  nvar,
int  size,
int  flag_fatal 
)

Core allocation of an array of double

Returns
Pointer to the array of pointers to be allocated
Parameters
[in]nvarnumber of elements in the array
[in]sizenumber of double values
[in]flag_fatalerror status (1 = the program stops)

◆ mem_tab_free()

double** mem_tab_free ( double **  tab,
int  nvar 
)

Core deallocation of an array of pointers

Returns
Pointer to the freed array
Parameters
[in]tabarray of pointers to be freed
[in]nvarNumber of elements in the array

◆ memory_leak_report()

void memory_leak_report ( void  )

Report Memory Leak

◆ memory_leak_reset()

void memory_leak_reset ( void  )

Reset the Memory Leak processing structure

◆ memory_leak_set()

void memory_leak_set ( int  flag)

Set the memory leak mechanism

Parameters
[in]flagActivation flag

◆ memory_status()

void memory_status ( const char *  title)

Print the status of the memory

Parameters
[in]titleTitle printed when checking memory

◆ st_mem_message()

static void st_mem_message ( const char *  call_file,
unsigned int  call_line,
const char *  format,
int  oper,
int  size 
)
static

Print a memory debugging message

Parameters
[in]call_fileName of the calling file
[in]call_lineLine in the calling file
[in]formatOutput format
[in]operSign of the operation (1 for allocation; -1 for free)
[in]sizeNumber of bytes treated
Remarks
The printout is performed only for memory chunks whose size is
larger than MEMORY_MIN_PT
It can be modified using keypair with keyword "Minimum_Debug_Size"

◆ st_mem_update()

static void st_mem_update ( int  size)
static

Update the Memory management

Parameters
[in]sizeSize of the allocation/deallocation

◆ st_memory_leak_add()

static void st_memory_leak_add ( const char *  call_file,
int  call_line,
size_t  size,
void *  ptr 
)
static

Add a Memory Chunk

Parameters
[in]call_fileName of the calling file
[in]call_lineLine of the calling function
[in]sizeDimension of the Chunk
[in]ptrAddress of the Chunk

◆ st_memory_leak_delete()

static void st_memory_leak_delete ( const char *  call_file,
unsigned int  call_line,
void *  ptr 
)
static

Delete a Memory Chunk

Parameters
[in]call_fileName of the calling file
[in]call_lineLine in the calling file
[in]ptrAddress of the Chunk to be freed

◆ st_time_chunk_close()

static void st_time_chunk_close ( void  )
static

Close the current Time Chunk

◆ time_chunk_add()

void time_chunk_add ( const char *  call_name)

Initialize a Time Chunk

Parameters
[in]call_nameName of the Chunk

◆ time_report()

void time_report ( void  )

Report the Time Stats

◆ time_reset()

void time_reset ( void  )

Reset the Time

◆ time_start()

void time_start ( void  )

Initialize the Timer

Variable Documentation

◆ MemLeak

MemChunk** MemLeak = NULL
static

◆ MEMORY_DEBUG

int MEMORY_DEBUG = 0
static

◆ MEMORY_LEAK

int MEMORY_LEAK = 0
static

◆ MEMORY_MAX

int MEMORY_MAX = 0
static

◆ MEMORY_MIN_PT

int MEMORY_MIN_PT = 1000000
static

◆ MEMORY_TOTAL

int MEMORY_TOTAL = 0
static

◆ NB_MEM_CHUNK

int NB_MEM_CHUNK = 0
static

◆ NB_TIME_CHUNK

int NB_TIME_CHUNK = 0
static

◆ TIME_CURRENT

hrc::time_point TIME_CURRENT = hrc::time_point()
static

◆ TIME_FOCUS

int TIME_FOCUS = -1
static

◆ TimeStat

TimeChunk** TimeStat = NULL
static