Skip to content

AllocatorFree

Description

Free memory through an allocator.

Parameters

Name Direction Description
alloc in,out Allocator that owns the allocation
ptr in Pointer to the allocation, or NULL
bytes in Allocation size in bytes
alignment in Allocation alignment in bytes

Success

Function cannot fail.

Failure

No action is taken when ptr or alloc is invalid.

Usage example (Cross-references)

Usage examples (Cross-references)
        if (*zs) {
            Allocator alloc = DefaultAllocator();
            AllocatorFree(&alloc, (void *)*zs, ZstrLen(*zs) + 1, 1);
            *zs = NULL;
        }
        if (*zs) {
            Allocator allocator = alloc ? *alloc : DefaultAllocator();
            AllocatorFree(&allocator, (void *)*zs, ZstrLen(*zs) + 1, 1);
            *zs = NULL;
        }
    }
    
    void AllocatorFree(Allocator *alloc, void *ptr, size bytes, size alignment) {
        if (!ptr || !alloc || !alloc->deallocate) {
            return;
    
        if (previous) {
            AllocatorFree(allocator_ptr, previous, ZstrLen(previous) + 1, 1);
        }
            (void)IntToBytesBE(value, buffer, byte_len);
            if (!write_char_internal(o, fmt_info->flags, (const char *)buffer, byte_len)) {
                AllocatorFree(&o->allocator, buffer, byte_len * sizeof(u8), 1);
                return false;
            }
                return false;
            }
            AllocatorFree(&o->allocator, buffer, byte_len * sizeof(u8), 1);
            return true;
        }
        }
    
        AllocatorFree(&graph->allocator, data, item_size, graph_node_data_alignment(graph));
    }
            }
    
            AllocatorFree(&vec->allocator, vec->data, aligned_size * (vec->capacity + 1), vec->alignment);
        }
        aligned_size = vec_aligned_size(vec, item_size);
        if (vec->length == 0) {
            AllocatorFree(&vec->allocator, vec->data, aligned_size * (vec->capacity + 1), vec->alignment);
            vec->data     = NULL;
            vec->capacity = 0;
    
    static inline void free_list_node(GenericList *list, GenericListNode *node) {
        AllocatorFree(&list->allocator, node, sizeof(GenericListNode), list_alloc_alignment());
    }
    
    static inline void free_list_item(GenericList *list, void *item, u64 item_size) {
        AllocatorFree(&list->allocator, item, item_size, list_alloc_alignment());
    }
        }
    
        AllocatorFree(&list->allocator, data, item_size * item_count, list_alloc_alignment());
        return true;
    }
        ValidateBitVec(bitvec);
        if (bitvec->data) {
            AllocatorFree(&bitvec->allocator, bitvec->data, bitvec->byte_size, 1);
            bitvec->data = NULL;
        }
        if (bv->length == 0) {
            // Free all memory if empty
            AllocatorFree(&bv->allocator, bv->data, bv->byte_size, 1);
            bv->data      = NULL;
            bv->capacity  = 0;
    
        if (!prev_row || !curr_row) {
            AllocatorFree(&scratch, prev_row, (len2 + 1) * sizeof(u64), _Alignof(u64));
            AllocatorFree(&scratch, curr_row, (len2 + 1) * sizeof(u64), _Alignof(u64));
            AllocatorUnbind(&scratch);
        if (!prev_row || !curr_row) {
            AllocatorFree(&scratch, prev_row, (len2 + 1) * sizeof(u64), _Alignof(u64));
            AllocatorFree(&scratch, curr_row, (len2 + 1) * sizeof(u64), _Alignof(u64));
            AllocatorUnbind(&scratch);
            return false;
    
        *out = prev_row[len2];
        AllocatorFree(&scratch, prev_row, (len2 + 1) * sizeof(u64), _Alignof(u64));
        AllocatorFree(&scratch, curr_row, (len2 + 1) * sizeof(u64), _Alignof(u64));
        AllocatorUnbind(&scratch);
        *out = prev_row[len2];
        AllocatorFree(&scratch, prev_row, (len2 + 1) * sizeof(u64), _Alignof(u64));
        AllocatorFree(&scratch, curr_row, (len2 + 1) * sizeof(u64), _Alignof(u64));
        AllocatorUnbind(&scratch);
        clear_map(map, entry_size, key_offset, key_size, value_offset, value_size, hash_offset);
    
        AllocatorFree(&map->allocator, map->entries, map->capacity * entry_size, map_storage_alignment());
        AllocatorFree(&map->allocator, map->states, map->capacity * sizeof(u8), map_storage_alignment());
        AllocatorUnbind(&map->allocator);
    
        AllocatorFree(&map->allocator, map->entries, map->capacity * entry_size, map_storage_alignment());
        AllocatorFree(&map->allocator, map->states, map->capacity * sizeof(u8), map_storage_alignment());
        AllocatorUnbind(&map->allocator);
    
        if ((map->length == 0) && (n == 0)) {
            AllocatorFree(&map->allocator, map->entries, map->capacity * entry_size, map_storage_alignment());
            AllocatorFree(&map->allocator, map->states, map->capacity * sizeof(u8), map_storage_alignment());
            map->entries    = NULL;
        if ((map->length == 0) && (n == 0)) {
            AllocatorFree(&map->allocator, map->entries, map->capacity * entry_size, map_storage_alignment());
            AllocatorFree(&map->allocator, map->states, map->capacity * sizeof(u8), map_storage_alignment());
            map->entries    = NULL;
            map->states     = NULL;
    
        if (!new_entries || !new_states) {
            AllocatorFree(&map->allocator, new_entries, new_capacity * entry_size, map_storage_alignment());
            AllocatorFree(&map->allocator, new_states, new_capacity * sizeof(u8), map_storage_alignment());
            return false;
        if (!new_entries || !new_states) {
            AllocatorFree(&map->allocator, new_entries, new_capacity * entry_size, map_storage_alignment());
            AllocatorFree(&map->allocator, new_states, new_capacity * sizeof(u8), map_storage_alignment());
            return false;
        }
        }
    
        AllocatorFree(&map->allocator, old_entries, old_capacity * entry_size, map_storage_alignment());
        AllocatorFree(&map->allocator, old_states, old_capacity * sizeof(u8), map_storage_alignment());
    
        AllocatorFree(&map->allocator, old_entries, old_capacity * entry_size, map_storage_alignment());
        AllocatorFree(&map->allocator, old_states, old_capacity * sizeof(u8), map_storage_alignment());
    
        (void)value_offset;
                hash
            )) {
            AllocatorFree(&map->allocator, temp_entry, entry_size, map_storage_alignment());
            return false;
        }
        (void)map_remove_all(map, key, entry_size, key_offset, key_size, value_offset, value_size, hash_offset);
        map_insert_raw_entry(map, temp_entry, entry_size, key_offset, key_size, hash_offset);
        AllocatorFree(&map->allocator, temp_entry, entry_size, map_storage_alignment());
        return true;
    }
                    map->value_copy_deinit(temp_value, &map->allocator);
                }
                AllocatorFree(&map->allocator, temp_value, value_size, map_storage_alignment());
                return false;
            }
        if (map->value_copy_init) {
            MemCopy(dst_value, temp_value, value_size);
            AllocatorFree(&map->allocator, temp_value, value_size, map_storage_alignment());
        } else {
            MemCopy(dst_value, value, value_size);
        CloseHandle(proc->pi.hProcess);
    #endif
        AllocatorFree(&allocator, proc, sizeof(SysProc), _Alignof(SysProc));
    }
    #endif
        MemSet(m, 0, sizeof(SysMutex));
        AllocatorFree(&allocator, m, sizeof(SysMutex), _Alignof(SysMutex));
    }
        {
            Allocator allocator = DefaultAllocator();
            AllocatorFree(&allocator, buffer, capacity, 1);
        }
        unlink(path);
                 capacity >= file_size + 1;
    
        AllocatorFree(&allocator, buffer, capacity, 1);
        unlink(path);
        return result;
Last updated on