DoxigAlpha

create

Creates a new item and adds it to the memory pool.

Function parameters

Parameters

#
pool:*Pool

Type definitions in this namespace

Types

#

A memory pool that can allocate objects of a single type very quickly.

Functions

#
MemoryPool
A memory pool that can allocate objects of a single type very quickly.
MemoryPoolAligned
A memory pool that can allocate objects of a single type very quickly.
MemoryPoolExtra
A memory pool that can allocate objects of a single type very quickly.

Error sets in this namespace

Error Sets

#

Source

Implementation

#
pub fn create(pool: *Pool) !ItemPtr {
    const node = if (pool.free_list) |item| blk: {
        pool.free_list = item.next;
        break :blk item;
    } else if (pool_options.growable)
        @as(NodePtr, @ptrCast(try pool.allocNew()))
    else
        return error.OutOfMemory;

    const ptr = @as(ItemPtr, @ptrCast(node));
    ptr.* = undefined;
    return ptr;
}