uLib
User mode C/C++ extended API library for Win32 programmers.
|
The mem_Nnn functions provide solid heap management.
#include <uLib/MemFunc.h>
The mem_Alloc() and mem_Realloc() functions go to considerable length to succeed,
including coalescing the heap to satisfy failed allocations, and mem_Free()
wraps deallocation in SEH (compiler permitting) to avoid termination-by-mistake.
Groups | |
Page Buffers | |
Page aligned virtual memory. | |
Physical Memory (AWE) | |
Allocation of physical memory. | |
Classes | |
class | SharedMem |
Interprocess shared memory. More... | |
Functions | |
void * | mem_Alloc (size_t Bytes) |
void * | mem_Realloc (void *pBlk, size_t Bytes) |
void * | mem_Free (void *pBlk) |
bool | mem_Compact () |
Variables | |
HANDLE | app_Heap |
void* mem_Alloc | ( | size_t | Bytes | ) |
Allocate a block from the app_Heap.
Bytes | Size to allocate. If zero, a NULL pointer is returned. |
Note: The mem_Alloc() and mem_Realloc() functions both try to coalesce the heap if an allocation fails,
and if a retry fails, validate the whole heap before they give up.
Definition at line 33 of file MemFunc.cpp.
void* mem_Realloc | ( | void * | pBlk, |
size_t | Bytes | ||
) |
Reallocate an existing memory block.
Note: Guaranteed zero,null contract, forever.
(C23 'victims' will appreciate the age proven 'realloc' compliance.)
pBlk | Block ptr. If NULL, mem_Alloc is invoked. |
Bytes | Size to allocate. If zero, and pBlk is not null, invoke mem_Free. |
Definition at line 80 of file MemFunc.cpp.
void* mem_Free | ( | void * | pBlk | ) |
Free a heap block and return NULL on success, or pBlk on error.
The deallocation is wrapped in SEH (compiler permitting) to avoid termination-by-mistake from invalid block pointers.
Note: mem_Free is NULL-safe.
Definition at line 124 of file MemFunc.cpp.
bool mem_Compact | ( | ) |
mem_Compact() coalesces free blocks and decommits unused pages.
This is done using HeapCompact(), which is fairly expensive, so don't overuse.
Definition at line 150 of file MemFunc.cpp.
HANDLE app_Heap |
The heap used by the mem_Nnn functions.
The app_Heap is globally initialized with GetProcessHeap during startup.
However, nothing prevents you from changing it with HeapCreate if you prefer a customized heap.
Just be sure to do it before using any mem_Nnn functions.
Definition at line 12 of file MemFunc.cpp.