|
CX Framework
Cross-platform C utility framework
|
Functions | |
| size_t | xaSize (void *ptr) |
| size_t | xaOptSize (size_t sz) |
Functions for querying allocation sizes and optimal size classes.
| 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.
| sz | Requested size in bytes |
| 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.
| ptr | Pointer to allocated memory |