Open Files 5.3.0
Multi-Platform Event-Driven Application Framework
heap.h File Reference
#include "ofc/core.h"
#include "ofc/types.h"
Include dependency graph for heap.h:

Go to the source code of this file.

Functions

OFC_CORE_LIB OFC_VOID ofc_heap_load (OFC_VOID)
 
OFC_CORE_LIB OFC_VOID ofc_heap_unload (OFC_VOID)
 
OFC_CORE_LIB OFC_VOID ofc_free (OFC_LPVOID mem)
 
OFC_CORE_LIB OFC_VOID ofc_heap_check_alloc (OFC_LPCVOID mem)
 
OFC_CORE_LIB OFC_VOID ofc_heap_dump_chunk (OFC_LPVOID mem)
 
OFC_CORE_LIB OFC_LPVOID ofc_malloc (OFC_SIZET size)
 
OFC_CORE_LIB OFC_LPVOID ofc_calloc (OFC_SIZET nmemb, OFC_SIZET size)
 
OFC_CORE_LIB OFC_LPVOID ofc_realloc (OFC_LPVOID ptr, OFC_SIZET size)
 
OFC_CORE_LIB OFC_VOID ofc_heap_dump_stats (OFC_VOID)
 
OFC_CORE_LIB OFC_VOID ofc_heap_dump (OFC_VOID)
 
OFC_CORE_LIB OFC_VOID ofc_heap_snap (OFC_VOID)
 

Function Documentation

◆ ofc_calloc()

OFC_CORE_LIB OFC_LPVOID ofc_calloc ( OFC_SIZET  nmemb,
OFC_SIZET  size 
)

Allocate and initiaize chunk of memory

Parameters
nmembNumber of structure to allocate
sizesize of structure
Returns
Pointer to chunk

◆ ofc_free()

OFC_CORE_LIB OFC_VOID ofc_free ( OFC_LPVOID  mem)

Deallocate a chunk of memory

This may be mapped to a free on many platforms.

Parameters
memA pointer to the memory to deallocate.
Examples
test_dg.c, test_event.c, test_file.c, test_path.c, test_stream.c, test_thread.c, test_timer.c, and test_waitq.c.

◆ ofc_heap_check_alloc()

OFC_CORE_LIB OFC_VOID ofc_heap_check_alloc ( OFC_LPCVOID  mem)

Check the allocation of a heap.

This will crash if the memory is not allocated

Parameters
memPointer to memory chunk

◆ ofc_heap_dump()

OFC_CORE_LIB OFC_VOID ofc_heap_dump ( OFC_VOID  )

Dump Heap Trace

This will print to the console a record for each chunk of memory that had been allocated includding who allocated it, the address of the chunk and the size of the chunk.

◆ ofc_heap_dump_chunk()

OFC_CORE_LIB OFC_VOID ofc_heap_dump_chunk ( OFC_LPVOID  mem)

Dump the debug status of a memory chunk

Parameters
memPointer to memory chunk

◆ ofc_heap_dump_stats()

OFC_CORE_LIB OFC_VOID ofc_heap_dump_stats ( OFC_VOID  )

Dump Heap Stats Usuage

This will print to the console the number of bytes used as well as the maximum number of bytes that had been used

◆ ofc_heap_load()

OFC_CORE_LIB OFC_VOID ofc_heap_load ( OFC_VOID  )

Initialize the Heap

This function is only called by ofc_init. It will initialize the heap for use. This may be a noop on many platforms

◆ ofc_heap_snap()

OFC_CORE_LIB OFC_VOID ofc_heap_snap ( OFC_VOID  )

Snap the Heap

Mark all allocated blocks in the heap as previously allocated. Only those chunks that are 'not snapped' will be printed upon a dump

◆ ofc_heap_unload()

OFC_CORE_LIB OFC_VOID ofc_heap_unload ( OFC_VOID  )

Unload the heap

◆ ofc_malloc()

OFC_CORE_LIB OFC_LPVOID ofc_malloc ( OFC_SIZET  size)

Allocate a chunk of memory

This may be mapped to a malloc on many platforms

Parameters
sizesize of the memory block to allocate
Returns
Nothing
Examples
test_dg.c, test_event.c, test_file.c, test_path.c, test_stream.c, test_thread.c, test_timer.c, and test_waitq.c.

◆ ofc_realloc()

OFC_CORE_LIB OFC_LPVOID ofc_realloc ( OFC_LPVOID  ptr,
OFC_SIZET  size 
)

Change the size (reallocate) a chunk of memory

This may be mapped to a realloc on many platforms

Parameters
ptrPointer to the initial chunk of memory
sizesize of the new memory block
Returns
Pointer to the new memory block.
Remarks
Reallocating a chunk of memory to a size within the same power of two 2^x to the 2^(x+1) will return the pointer passed in.