VecTryReduceSpace
Description
Try to shrink the allocated capacity of the vector back to its current length. Use when previous growth left a large unused tail.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in,out | Vector handle. |
Success
Returns true. The vector’s capacity now equals its current length; any over-allocated tail bytes have been returned to the allocator.
Failure
Returns false on allocation failure during the shrink reallocation. The vector is unchanged (length, capacity, and data pointer are all preserved).
Usage example (Cross-references)
Usage examples (Cross-references)
- In
VecCharPtr.c:197:
case VEC_CHAR_PTR_TRY_REDUCE_SPACE : {
VecTryReduceSpace(vec);
break;
}- In
VecStr.c:211:
case VEC_STR_TRY_REDUCE_SPACE : {
VecTryReduceSpace(vec);
break;
}- In
VecInt.c:143:
case VEC_INT_TRY_REDUCE_SPACE : {
VecTryReduceSpace(vec);
break;
}- In
Vec.Memory.c:17:
// Test VecTryReduceSpace function
bool test_vec_try_reduce_space(void) {
WriteFmt("Testing VecTryReduceSpace\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Vec.Memory.c:38:
// Try to reduce space
VecTryReduceSpace(&vec);
// Capacity should now be closer to the actual length
- In
Memory.h:40:
#define VecMustTryReduceSpace(v) \
do { \
if (!VecTryReduceSpace((v))) { \
LOG_FATAL("VecTryReduceSpace failed"); \
} \- In
Memory.h:41:
do { \
if (!VecTryReduceSpace((v))) { \
LOG_FATAL("VecTryReduceSpace failed"); \
} \
} while (0)- In
Memory.h:23:
/// TAGS: Str, Memory, ReduceSpace
///
#define StrTryReduceSpace(str) VecTryReduceSpace(str)
///
Last updated on