AllocatorRemap
Description
Resize an allocation, allowing relocation. May return a new pointer that differs from ptr. 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, or NULL. |
new_size |
in | Requested new size in bytes. |
Success
Returns the (possibly moved) pointer, or NULL when new_size is zero.
Failure
Returns NULL when the allocator can’t satisfy the request.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Allocator.h:503:
(((ptr) && (new_size) > 0 && AllocatorResize((self), (ptr), (new_size))) ? \
(ptr) : \
AllocatorRemap((self), (ptr), (new_size)))
///
- In
Dispatch.c:155:
Allocator a = mock_make(ALLOCATOR_EFFORT_RETRY, 2); // 3 attempts
mock_reset(1000);
void *p = AllocatorRemap(&a, mock_backing, 16);
return p == NULL && mock_remap_calls == 3;
}- In
Dispatch.c:163:
Allocator a = mock_make(ALLOCATOR_EFFORT_RETRY, 3); // 4 attempts
mock_reset(1000);
void *p = AllocatorRemap(&a, mock_backing, 16);
return p == NULL && mock_remap_calls == 4;
}- In
Dispatch.c:172:
Allocator a = mock_make(ALLOCATOR_EFFORT_RETRY, 3); // 4 attempts
mock_reset(1); // fail once, then succeed
void *p = AllocatorRemap(&a, mock_backing, 16);
return p != NULL && mock_remap_calls == 2;
}- In
Dispatch.c:185:
Allocator a = mock_make(ALLOCATOR_EFFORT_RETRY, 3);
mock_reset(1000); // remap always returns NULL
void *p = AllocatorRemap(&a, mock_backing, 0);
return p == NULL && mock_remap_calls == 1;
}- In
Dispatch.c:231:
Allocator a = mock_make_bad_magic();
mock_reset(0);
(void)AllocatorRemap(&a, mock_backing, 16); // real -> LOG_FATAL
return false;
}- In
Insert.c:315:
if (f->fail_now)
return NULL;
return AllocatorRemap(f->inner, ptr, new_size);
}
Last updated on