Skip to content
AllocatorRealloc

AllocatorRealloc

Description

Reallocate memory through an allocator. The allocator effort policy controls how many attempts are made before the reallocation is reported as failed.

Parameters

Name Direction Description
alloc in,out Allocator used for the reallocation
ptr in Existing allocation pointer, or NULL
old_size in Previous allocation size in bytes
new_size in Requested new allocation size in bytes
alignment in Required alignment in bytes

Success

Returns a pointer to the resized allocation, or NULL when new_size is zero.

Failure

Returns NULL when reallocation fails or allocator is invalid.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    void *AllocatorRealloc(Allocator *alloc, void *ptr, size old_size, size new_size, size alignment) {
        size  attempts;
        size  try_idx;
        u64   required_capacity = (u64)fsize + 1;
        if (*capacity < required_capacity) {
            buffer = AllocatorRealloc(active_allocator, buffer, *capacity, required_capacity, 1);
    
            if (!buffer) {
        if (n > vec->capacity) {
            size  old_capacity = (size)vec->capacity;
            char *ptr          = (char *)AllocatorRealloc(
                &vec->allocator,
                vec->data,
            return true;
        } else {
            char *ptr = (char *)AllocatorRealloc(
                &vec->allocator,
                vec->data,
            return true;
        u64 new_byte_size = BYTES_FOR_BITS(n);
        u8 *new_data      = (u8 *)AllocatorRealloc(&bitvec->allocator, bitvec->data, bitvec->byte_size, new_byte_size, 1);
    
        if (!new_data) {
        }
    
        u8 *new_data = (u8 *)AllocatorRealloc(&bv->allocator, bv->data, bv->byte_size, new_byte_size, 1);
        if (!new_data) {
            // Realloc failed, but that's okay for shrinking
Last updated on