Skip to content
AllocatorAlloc

AllocatorAlloc

Description

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

Parameters

Name Direction Description
alloc in,out Allocator used for the allocation
bytes in Number of bytes to allocate
alignment in Required alignment in bytes
zeroed in Whether the allocated region must be zero-initialized

Success

Returns a writable pointer to allocated memory.

Failure

Returns NULL when allocation fails or allocator is invalid.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        env_var = (char *)AllocatorAlloc(&allocator, requiredSize, 1, false);
        if (!env_var) {
            return NULL;
            len++;
    
        char *new_str = (char *)AllocatorAlloc(&alloc, len + 1, 1, false);
        if (!new_str) {
            LOG_SYS_ERROR("allocator allocate failed");
    }
    
    void *AllocatorAlloc(Allocator *alloc, size bytes, size alignment, bool zeroed) {
        size  attempts;
        size  try_idx;
            }
    
            u8 *buffer = (u8 *)AllocatorAlloc(&o->allocator, byte_len * sizeof(u8), 1, true);
    
            if (!buffer) {
    static void *graph_alloc_node_data(GenericGraph *graph, size item_size) {
        graph_validate_alignment(graph);
        return AllocatorAlloc(&graph->allocator, item_size, graph_node_data_alignment(graph), true);
    }
    
    static inline GenericListNode *alloc_list_node(GenericList *list) {
        return AllocatorAlloc(&list->allocator, sizeof(GenericListNode), list_alloc_alignment(), true);
    }
    
    static inline void *alloc_list_item(GenericList *list, u64 item_size) {
        return AllocatorAlloc(&list->allocator, item_size, list_alloc_alignment(), true);
    }
    
        item_count = list->length;
        data       = AllocatorAlloc(&list->allocator, item_size * item_count, list_alloc_alignment(), false);
        if (!data) {
            return false;
        }
    
        result.data = (u8 *)AllocatorAlloc(&result.allocator, BITVEC_BYTES_FOR_BITS(cap), 1, true);
        if (!result.data) {
            return result;
    
        // Dynamic programming matrix
        u64 *prev_row = AllocatorAlloc(&scratch, (len2 + 1) * sizeof(u64), _Alignof(u64), false);
        u64 *curr_row = AllocatorAlloc(&scratch, (len2 + 1) * sizeof(u64), _Alignof(u64), false);
        // Dynamic programming matrix
        u64 *prev_row = AllocatorAlloc(&scratch, (len2 + 1) * sizeof(u64), _Alignof(u64), false);
        u64 *curr_row = AllocatorAlloc(&scratch, (len2 + 1) * sizeof(u64), _Alignof(u64), false);
    
        if (!prev_row || !curr_row) {
        old_capacity = map->capacity;
    
        new_entries = AllocatorAlloc(&map->allocator, new_capacity * entry_size, map_storage_alignment(), true);
        new_states  = AllocatorAlloc(&map->allocator, new_capacity * sizeof(u8), map_storage_alignment(), true);
    
        new_entries = AllocatorAlloc(&map->allocator, new_capacity * entry_size, map_storage_alignment(), true);
        new_states  = AllocatorAlloc(&map->allocator, new_capacity * sizeof(u8), map_storage_alignment(), true);
    
        if (!new_entries || !new_states) {
    
        hash       = map_hash_key(map, key, key_size);
        temp_entry = AllocatorAlloc(&map->allocator, entry_size, map_storage_alignment(), true);
        if (!temp_entry) {
            return false;
    
        if (map->value_copy_init) {
            temp_value = AllocatorAlloc(&map->allocator, value_size, map_storage_alignment(), true);
            if (!temp_value) {
                return false;
    
        Allocator allocator = DefaultAllocator();
        SysProc  *proc      = (SysProc *)AllocatorAlloc(&allocator, sizeof(SysProc), _Alignof(SysProc), true);
    
        if (!proc) {
    
        Allocator allocator = DefaultAllocator();
        SysProc  *proc      = (SysProc *)AllocatorAlloc(&allocator, sizeof(SysProc), _Alignof(SysProc), true);
    
        if (!proc) {
    SysMutex *SysMutexCreate(void) {
        Allocator allocator = DefaultAllocator();
        SysMutex *m         = (SysMutex *)AllocatorAlloc(&allocator, sizeof(SysMutex), _Alignof(SysMutex), true);
    
        if (!m) {
        }
    
        buffer = (char *)AllocatorAlloc(&allocator, 4, 1, true);
        if (!buffer) {
            unlink(path);
Last updated on