mkernel 0.0.1
Micro-kernel framework, everything as a module
memtrack.h File Reference

Memory block metadata tracking headers. More...

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

Go to the source code of this file.

Classes

struct  MemBlock
 Memory block metadata list item. More...
 

Typedefs

typedef struct MemBlock TMemBlock
 Memory block metadata list item. 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 )()
 Functor to list allocated memory blocks metadata. More...
 
uint64_t(* memtrack_getallocatedblocks )()
 Functor to get the number of allocated blocks. More...
 
uint64_t(* memtrack_getallocatedRAM )()
 Functor to get the total RAM size allocated. More...
 
size_t(* memtrack_getblocksize )(const void *p_Ptr)
 Functor to get size of a specific memory block. More...
 

Detailed Description

Memory block metadata tracking headers.

Date
25/09/2006
Author
François Cerbelle (Fanfan), franc.nosp@m.ois@.nosp@m.cerbe.nosp@m.lle..nosp@m.net

Originally inspired by "L'art du code", Steve Maguire, Microsoft Press

Definition in file memtrack.h.

Typedef Documentation

◆ TMemBlock

typedef struct MemBlock TMemBlock

Memory block metadata list item.

Double linked list item to store memory block metadata

Variable Documentation

◆ memtrack_addblock

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 
)
extern

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.

Parameters
[in]p_PtrAllocated memory block pointer
[in]p_SizeAllocated 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
Returns
Registration status
Return values
0if succeeded,
1if not possible.

Definition at line 593 of file memtrack.c.

◆ memtrack_delblock

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 
)
extern

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.

Parameters
[in]p_PtrAllocated 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
Returns
Registration status
Return values
0if succeeded,
!0if not possible.

Definition at line 603 of file memtrack.c.

◆ memtrack_dumpblocks

uint64_t(* memtrack_dumpblocks) () ( )
extern

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.

Returns
Number of registered blocks (counted)
Return values
0if succeeded,
!0if not possible.

Definition at line 612 of file memtrack.c.

◆ memtrack_getallocatedblocks

uint64_t(* memtrack_getallocatedblocks) () ( )
extern

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.

Returns
Number of registered blocks

Definition at line 615 of file memtrack.c.

◆ memtrack_getallocatedRAM

uint64_t(* memtrack_getallocatedRAM) () ( )
extern

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.

Returns
Total RAM size in bytes

Definition at line 618 of file memtrack.c.

◆ memtrack_getblocksize

size_t(* memtrack_getblocksize) (const void *p_Ptr) ( const void *  p_Ptr)
extern

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.

Parameters
[in]p_PtrAllocated and tracked memory block pointer
Returns
Memory block size in bytes

Definition at line 621 of file memtrack.c.