tape-kernel 1.0
a modular modern independent kernel
Loading...
Searching...
No Matches
heap.h File Reference
#include "../lib/types.h"
Include dependency graph for heap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  arena_t
 the arena_t type More...

Macros

#define hinit   __hinit
#define alc   __alc
#define res   __res
#define anew   __anew

Functions

void __hinit (arena_t *heap, void *start, uint32_t size)
 initializes a central heap rather then child arena
void * __alc (arena_t *heap, uint32_t size)
 allocates memory to a heap
void __res (arena_t *heap)
 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

Macro Definition Documentation

◆ alc

#define alc   __alc

Definition at line 25 of file heap.h.

Referenced by ___init(), __anew(), __fsadd(), __fsinit(), cmd_alloc(), and malloc().

◆ anew

#define anew   __anew

Definition at line 27 of file heap.h.

Referenced by ___init().

◆ hinit

#define hinit   __hinit

Definition at line 24 of file heap.h.

Referenced by ___init(), and __anew().

◆ res

#define res   __res

Definition at line 26 of file heap.h.

Referenced by __shell().

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.