CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Size Introspection

Functions

size_t xaSize (void *ptr)
 
size_t xaOptSize (size_t sz)
 

Detailed Description

Functions for querying allocation sizes and optimal size classes.

Function Documentation

◆ xaOptSize()

size_t xaOptSize ( size_t  sz)

Returns the optimal size to allocate to fit a given number of bytes.

This returns the underlying size class that fits the given number of bytes. This is most useful when the allocator is in secure mode to determine how much bigger a buffer can be allocated without moving to the next size class, since in that mode the difference between the requested size and actual allocated size is NOT usable by the caller due to secure padding.

Parameters
szRequested size in bytes
Returns
Optimal allocation size for the size class

◆ xaSize()

size_t xaSize ( void *  ptr)

Returns the size of memory at ptr.

In normal (max performance) mode, this will have a lower bound at the number of bytes that were required by xaAlloc, but may be more. If more, it is safe to use the extra space without reallocating.

In secure mode, this will always return the exact number of bytes that were requested by the original allocation. The reason is that in secure mode, any slack space in the allocation is filled with padding and used to check for buffer overruns.

Parameters
ptrPointer to allocated memory
Returns
Size of the allocation in bytes
See also
xaOptSize()