X11workbench Toolkit
1.0
|
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... | |
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.
void* WBAlloc | ( | int | nSize | ) |
High performance memory sub-allocator 'allocate'.
nSize | The length of memory being requested |
Header File: platform_helper.h
Definition at line 1190 of file platform_helper.c.
int WBAllocUsableSize | ( | void * | pBuf | ) |
High performance memory sub-allocator, similar to 'malloc_usable_size'.
pBuf | A pointer to the previously sub-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.
void WBFree | ( | void * | pBuf | ) |
High performance memory sub-allocator 'free'.
pBuf | A pointer to the previously sub-allocated memory |
Header File: platform_helper.h
Definition at line 1274 of file platform_helper.c.
void* WBReAlloc | ( | void * | pBuf, |
int | nNewSize | ||
) |
High performance memory sub-allocator 're-allocate'.
pBuf | A pointer to the previously sub-allocated memory |
nNewSize | The desired 'new' size of the memory block |
Header File: platform_helper.h
Definition at line 1315 of file platform_helper.c.
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.