AllocatorResize
Description
Try to grow / shrink an allocation in place. The pointer never moves. Same dispatch shape as AllocatorAlloc: typed paths skip ValidateAllocator and the retry loop; the Allocator * arm routes through the dyn wrapper. Stats accounting lives inline in each typed body either way.
Parameters
| Name | Direction | Description |
|---|---|---|
self |
in,out | Typed allocator pointer or Allocator *. |
ptr |
in | Existing allocation pointer (non-NULL). |
new_size |
in | Requested new size in bytes (non-zero). |
Success
Returns 1. ptr remains valid for new_size bytes.
Failure
Returns 0. The allocation is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Allocator.h:501:
///
#define AllocatorRealloc(self, ptr, new_size) \
(((ptr) && (new_size) > 0 && AllocatorResize((self), (ptr), (new_size))) ? \
(ptr) : \
AllocatorRemap((self), (ptr), (new_size)))- In
AllocDebug.c:950:
bool ok = (p != NULL);
// debug_allocator_resize unconditionally returns 0 (refuses).
i8 r = AllocatorResize(adbg, p, 128);
ok = ok && (r == 0);
// The allocation is untouched -- still one live record of 64 bytes.
// mutant) would make this return 0 instead of aborting.
dbg.base.__magic = 0;
(void)AllocatorResize(&dbg, p, 32); // -> LOG_FATAL via debug_validate_self
return false; // unreachable
}- In
Dispatch.c:223:
static bool test_al_resize_validates_magic(void) {
Allocator a = mock_make_bad_magic();
(void)AllocatorResize(&a, mock_backing, 16); // real -> LOG_FATAL
return false;
}- In
Insert.c:308:
static i8 fail_alloc_resize(Allocator *self, void *ptr, size new_size) {
FailAlloc *f = (FailAlloc *)(void *)self;
return AllocatorResize(f->inner, ptr, new_size);
}
Last updated on