tape-kernel 1.0
a modular modern independent kernel
Loading...
Searching...
No Matches
heap.c File Reference
#include "heap.h"
#include "../lib/types.h"
#include "../lib/err.h"
Include dependency graph for heap.c:

Go to the source code of this file.

Functions

void __hinit (arena_t *arena, void *start, uint32_t size)
 initializes a central heap rather then child arena
void * __alc (arena_t *arena, uint32_t size)
 allocates memory to a heap
void __res (arena_t *arena)
 resets a arena or heap by setting current to start and overriding data
arena_t__anew (arena_t *parent, uint32_t size)
 creates a child arena under a central heap

Function Documentation

◆ __alc()

void * __alc ( arena_t * arena,
uint32_t size )

allocates memory to a heap

alc is a function that allocates memory from a central heap

Parameters
arena,theptr to the arena to allocate from
size,theamount to allocate

using alc is done with

#include "../mem/heap.h" //or just heap.h
void* myspace = alc(&myarena, 16); //allocate 16 bytes
#define alc
Definition heap.h:25
See also
res(), anew()

Definition at line 51 of file heap.c.

References assert, arena_t::current, NULL, panic, arena_t::size, and arena_t::start.

◆ __anew()

arena_t * __anew ( arena_t * parent,
uint32_t size )

creates a child arena under a central heap

anew is a function that makes a child arena under a parent heap

Parameters
parent,theptr to the parent arena
size,thesize of the arena

using anew is done with

#include "../mem/heap.h" //or just heap.h
#define MYARENA_SIZE (256 * 1024) //256kb child arena
arena_t *myarena
myarena = anew(&myheap, MYARENA_SIZE);
#define anew
Definition heap.h:27
the arena_t type
Definition heap.h:17

and you can reset this new arena or use it!

See also
res()

Definition at line 105 of file heap.c.

References alc, assert, hinit, and NULL.

◆ __hinit()

void __hinit ( arena_t * arena,
void * start,
uint32_t size )

initializes a central heap rather then child arena

hinit is a function used to initliaze a new central heap, like kheap

Parameters
arena,inhinit this is the ptr to your heap
start,thisshould be a buffer like 'static uint8_t mem[HEAP_SIZE]' using the size of your heap
size,thesize of the heap using 'sizeof(mem)'

using hinit is done with

#include "../mem/heap.h" //or just heap.h
#define MYHEAP_SIZE (1024 * 1024) //the size of your heap, in this case 1mb, this is in bytes, so 1024 is 1kb, 1024 * 1024 is 1mb, and etc
arena_t myheap; //your heap
static uint8_t mymem[MYHEAP_SIZE] //that actual size
//now lets call hinit
hinit(&myheap, mymem, sizeof(mymem));
#define hinit
Definition heap.h:24
unsigned char uint8_t
Definition types.h:28

it initializes the heap by making the start and size be your set size but the current heap addr the start

See also
kheap, alc(), res(), anew(), arena_t

Definition at line 30 of file heap.c.

References arena_t::current, arena_t::size, and arena_t::start.

◆ __res()

void __res ( arena_t * arena)

resets a arena or heap by setting current to start and overriding data

Parameters
arena,thearena or heap to reset

Definition at line 82 of file heap.c.

References arena_t::current, and arena_t::start.