mkernel 0.0.2
Micro-kernel framework, everything as a module
|
Memory block metadata tracking implementation. More...
Go to the source code of this file.
Functions | |
void | memtrack_reset () |
Memory block metadata list reset. More... | |
Variables | |
unsigned int(* | memtrack_addblock )(const void *p_Ptr, const size_t p_Size, const char *p_File, const int p_Line, const char *p_CompilDate, const char *p_CompilTime, const char *p_Function) |
Functor to register an allocated memory block metadata. More... | |
unsigned int(* | memtrack_delblock )(const void *p_Ptr, const char *p_File, const int p_Line, const char *p_CompilDate, const char *p_CompilTime, const char *p_Function) |
Functor to unregister an allocated memory block metadata. More... | |
uint64_t(* | memtrack_dumpblocks )() = memtrack_dumpblocks_preinit |
Functor to list allocated memory blocks metadata. More... | |
uint64_t(* | memtrack_getallocatedblocks )() = memtrack_getallocatedblocks_preinit |
Functor to get the number of allocated blocks. More... | |
uint64_t(* | memtrack_getallocatedRAM )() = memtrack_getallocatedRAM_preinit |
Functor to get the total RAM size allocated. More... | |
size_t(* | memtrack_getblocksize )(const void *p_Ptr) = memtrack_getblocksize_preinit |
Functor to get size of a specific memory block. More... | |
Memory block metadata tracking implementation.
Originally inspired by "L'art du code", Steve Maguire, Microsoft Press
Definition in file memtrack.c.
void memtrack_reset | ( | ) |
Memory block metadata list reset.
This function is not defined in the header file because it should never be used. It is exported because it is used by the unit tests. NEVER USE IT, it will crash your code.
Definition at line 99 of file memtrack.c.
unsigned int(* memtrack_addblock) (const void *p_Ptr, const size_t p_Size, const char *p_File, const int p_Line, const char *p_CompilDate, const char *p_CompilTime, const char *p_Function) | ( | const void * | p_Ptr, |
const size_t | p_Size, | ||
const char * | p_File, | ||
const int | p_Line, | ||
const char * | p_CompilDate, | ||
const char * | p_CompilTime, | ||
const char * | p_Function | ||
) |
Functor to register an allocated memory block metadata.
Create and adds a memory block metadata record in the tracking system to detect memory leaks. It performs some basic sanity checks. The filename, compilation date and compilation time can not be null or empty, the line number can not be 0, the memory pointer to store can not be NULL or already registered and its size needs to be greater than 0.
The function is called from memdbg.c functions used in the application code thru memory.h macros. The macro automatically fills the filename, line number, compilation date and time, and function name (using GCC's non-ansi __func_ extension).
This functor is used to implement a lazy initialization. It initialy reference a temporary function to trigger memtrack initialization before calling the actual function. Then, it references the actual function directly to avoid any useless tests.
[in] | p_Ptr | Allocated memory block pointer |
[in] | p_Size | Allocated memory block size |
[in] | p_File | : Source file |
[in] | p_Line | : Source line number |
[in] | p_CompilDate | : File compilation date |
[in] | p_CompilTime | : File compilation time |
[in] | p_Function | : Source function name |
0 | if succeeded, |
1 | if not possible. |
Definition at line 593 of file memtrack.c.
unsigned int(* memtrack_delblock) (const void *p_Ptr, const char *p_File, const int p_Line, const char *p_CompilDate, const char *p_CompilTime, const char *p_Function) | ( | const void * | p_Ptr, |
const char * | p_File, | ||
const int | p_Line, | ||
const char * | p_CompilDate, | ||
const char * | p_CompilTime, | ||
const char * | p_Function | ||
) |
Functor to unregister an allocated memory block metadata.
Find and delete a memory block metadata record in the tracking system. It performs some basic sanity checks. The filename, compilation date and compilation time can not be null or empty, the line number can not be 0, the memory pointer to remove can not be NULL, it needs to already be registered.
The function is called from memdbg.c functions used in the application code thru memory.h macros. The macro automatically fills the filename, line number, compilation date and time, and function name (using GCC's non-ansi __func_ extension).
This functor is used to implement a lazy initialization. It initialy reference a temporary function to trigger memtrack initialization before calling the actual function. Then, it references the actual function directly to avoid any useless tests.
[in] | p_Ptr | Allocated memory block pointer |
[in] | p_File | : Source file |
[in] | p_Line | : Source line number |
[in] | p_CompilDate | : File compilation date |
[in] | p_CompilTime | : File compilation time |
[in] | p_Function | : Source function name |
0 | if succeeded, |
!0 | if not possible. |
Definition at line 603 of file memtrack.c.
uint64_t(* memtrack_dumpblocks) () | ( | ) | = memtrack_dumpblocks_preinit |
Functor to list allocated memory blocks metadata.
Dumps all the metadata of the registered memory blocks to stderr.
This functor is used to implement a lazy initialization. It initialy reference a temporary function to trigger memtrack initialization before calling the actual function. Then, it references the actual function directly to avoid any useless tests.
0 | if succeeded, |
!0 | if not possible. |
Definition at line 612 of file memtrack.c.
uint64_t(* memtrack_getallocatedblocks) () | ( | ) | = memtrack_getallocatedblocks_preinit |
Functor to get the number of allocated blocks.
This function returns the value of the internal counter of allocated memory blocks metadata.
This functor is used to implement a lazy initialization. It initialy reference a temporary function to trigger memtrack initialization before calling the actual function. Then, it references the actual function directly to avoid any useless tests.
Definition at line 615 of file memtrack.c.
uint64_t(* memtrack_getallocatedRAM) () | ( | ) | = memtrack_getallocatedRAM_preinit |
Functor to get the total RAM size allocated.
This function returns the internal summ of all the allocated memory blocks which are registered.
This functor is used to implement a lazy initialization. It initialy reference a temporary function to trigger memtrack initialization before calling the actual function. Then, it references the actual function directly to avoid any useless tests.
Definition at line 618 of file memtrack.c.
size_t(* memtrack_getblocksize) (const void *p_Ptr) | ( | const void * | p_Ptr | ) | = memtrack_getblocksize_preinit |
Functor to get size of a specific memory block.
The function will search in the list for the specified pointer. If the pointer is not found, it will return 0, which is discriminent as the memtracker does not allow to track a zero sized block. The memtracker does not allow neither to track a NULL pointer, thus NULL will return 0. Otherwise, the function will return the memory block size.
This functor is used to implement a lazy initialization. It initialy reference a temporary function to trigger memtrack initialization before calling the actual function. Then, it references the actual function directly to avoid any useless tests.
[in] | p_Ptr | Allocated and tracked memory block pointer |
Definition at line 621 of file memtrack.c.