kiba-engine
Data Structures | Typedefs | Functions
linear.c File Reference

Linear allocator implementation. More...

#include <kiba/allocators/linear.h>
#include <kiba/core/log.h>
#include <kiba/core/memory.h>
Include dependency graph for linear.c:

Go to the source code of this file.

Data Structures

struct  linear_allocator_block
 Internal state of the linear_allocator. More...
 

Typedefs

typedef struct linear_allocator_block linear_allocator_block
 Internal state of the linear_allocator. More...
 

Functions

linear_allocator_blocklinear_allocator_block_create (usize size, linear_allocator_block *next)
 Create a new linear_allocator_block. More...
 
b8 linear_allocator_create (allocator *alloc, usize size)
 
void linear_allocator_destroy (allocator *alloc)
 
void * linear_allocator_allocate (allocator *alloc, usize size)
 
void linear_allocator_free (allocator *alloc, void *mem, usize size)
 
void linear_allocator_free_all (allocator *alloc)
 

Detailed Description

Linear allocator implementation.

Definition in file linear.c.

Typedef Documentation

◆ linear_allocator_block

Internal state of the linear_allocator.

Memory is managed as a linked list. The initial memory block provides at least the requested amount of memory. It will add a new block to the list if the old one is either full or a requested allocation cannot be served with the current blocks. New blocks are added to the start of the list.

Function Documentation

◆ linear_allocator_allocate()

void* linear_allocator_allocate ( allocator alloc,
usize  size 
)
See also
allocator_impl_allocate_fn

Definition at line 88 of file linear.c.

Here is the call graph for this function:

◆ linear_allocator_block_create()

linear_allocator_block * linear_allocator_block_create ( usize  size,
linear_allocator_block next 
)

Create a new linear_allocator_block.

Initializes cur_offset to 0.

Parameters
sizeminimum size of the memory area
nextthe next block in the linked list
Returns
pointer to a new linear_allocator_block or KB_NULL if unsuccessful

Definition at line 44 of file linear.c.

◆ linear_allocator_create()

b8 linear_allocator_create ( allocator alloc,
usize  size 
)
See also
allocator_impl_create_fn

Definition at line 60 of file linear.c.

Here is the call graph for this function:

◆ linear_allocator_destroy()

void linear_allocator_destroy ( allocator alloc)
See also
allocator_impl_destroy_fn

Definition at line 76 of file linear.c.

◆ linear_allocator_free()

void linear_allocator_free ( allocator alloc,
void *  mem,
usize  size 
)
See also
allocator_impl_free_fn

Definition at line 124 of file linear.c.

◆ linear_allocator_free_all()

void linear_allocator_free_all ( allocator alloc)
See also
allocator_impl_free_all_fn

Definition at line 131 of file linear.c.