X11workbench Toolkit  1.0
Memory sub-allocator for high performance dynamic memory management

Generic utility functions for allocating and manipulated memory buffers. More...

Functions

void * WBAlloc (int nSize)
 High performance memory sub-allocator 'allocate'. More...
 
void WBFree (void *pBuf)
 High performance memory sub-allocator 'free'. More...
 
int WBAllocUsableSize (void *pBuf)
 High performance memory sub-allocator, similar to 'malloc_usable_size'. More...
 
void * WBReAlloc (void *pBuf, int nNewSize)
 High performance memory sub-allocator 're-allocate'. More...
 
void WBSubAllocTrashMasher (void)
 High performance memory sub-allocator 'trash masher' - call periodically to minimize wasted memory. More...
 

Detailed Description

Generic utility functions for allocating and manipulated memory buffers.

The purpose of the high performance sub-allocator is to minimize memory fragmentation and related performance issues caused by 'malloc' and the related 'new' operator in C++. In some implementations, they may simply be an alias for the 'malloc' functions. In other implementations they can manage sub allocation via the OS. In still others, they can implement a complex but efficient memory sub-allocation scheme using virtual memory. Abstraction is the key, along with performance. The 'edit text' utilities are designed for hyper-efficient editing of extremely large text files.
Since I have seen 'malloc a boatload of tiny memory fragments' cause PERFORMANCE PROBLEMS in the past, I want to avoid that.

Function Documentation

◆ WBAlloc()

void* WBAlloc ( int  nSize)

High performance memory sub-allocator 'allocate'.

Parameters
nSizeThe length of memory being requested
Returns
A pointer to the allocated buffer, always aligned on a 'pointer size' boundary. Do NOT overrun the buffer!

Header File: platform_helper.h

Definition at line 1190 of file platform_helper.c.

◆ WBAllocUsableSize()

int WBAllocUsableSize ( void *  pBuf)

High performance memory sub-allocator, similar to 'malloc_usable_size'.

Parameters
pBufA pointer to the previously sub-allocated memory
Returns
The usable size of the allocated memory.

Use this function to determine how big a memory block REALLY is, particularly if 'malloc_usable_size' is supported. The sub-allocators use power-of-two allocation sizes in order to minimize the need to re-allocate blocks of memory. The assumption is that memory re-allocation is likely. To minimize the need to flip pointers around all of the time, and copy blocks of memory from one place to another via re-allocation, you can use this function to determine how much memory is REALLY available in the memory block. (this function is used internally within WBReAlloc(), and is generally 'advisory' when used for other purposes).

Header File: platform_helper.h

Definition at line 1251 of file platform_helper.c.

◆ WBFree()

void WBFree ( void *  pBuf)

High performance memory sub-allocator 'free'.

Parameters
pBufA pointer to the previously sub-allocated memory
Returns
void

Header File: platform_helper.h

Definition at line 1274 of file platform_helper.c.

◆ WBReAlloc()

void* WBReAlloc ( void *  pBuf,
int  nNewSize 
)

High performance memory sub-allocator 're-allocate'.

Parameters
pBufA pointer to the previously sub-allocated memory
nNewSizeThe desired 'new' size of the memory block
Returns
A pointer to the new allocated memory block, or NULL on error. If the return value is NOT NULL, the previous pointer becomes invalid.

Header File: platform_helper.h

Definition at line 1315 of file platform_helper.c.

◆ WBSubAllocTrashMasher()

void WBSubAllocTrashMasher ( void  )

High performance memory sub-allocator 'trash masher' - call periodically to minimize wasted memory.

Sub-allocation sometimes leaves 'holes' in memory. This function is intended to minimize that, by freeing up blocks of allocated memory that are no longer in use. It is not the same as 'garbage collection', but it may have the same basic effect. Call this function within the main message loop in the main thread.

Header File: platform_helper.h

Definition at line 1408 of file platform_helper.c.