summaryrefslogtreecommitdiff
path: root/mem/docs/framer.9.scd
blob: 1bc36709ec9aa3ab08678b1e58bdb78b4a0c885d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
MEM_FRAMER(9)

# NAME

*mem_framer_install*, *mem_framer_alloc*, *mem_framer_free* - allocator for fixed and aligned frames

# SYNOPSIS

```
#include <mem/framer.h>

typedef struct mem_framer MemFramer;

MemFramer *mem_framer_install(void *addr, usize end, uint blksz);
void *mem_framer_alloc(MemAllocator *self, usize n);
void mem_framer_free(MemAllocator *self, void *ptr);
```

# DESCRIPTION

*MemFramer* and its related functions is an implementation of mem_allocator(9) designed to manage the allocation and freeing of chunks of same size - they are called _frames_ - that are boundary aligned on multiples of that size.

*MemFramer* is a linked-list allocator, meaning that when a frame is requested, it can either pop the frame from a free list (a linked list of frames that have previously been freed), or bump a new frame from the region of usable memory that it manages.

## Installing

A *MemFramer* can be installed in a particular region of usable memory to manage it using *mem_framer_install()*. It accepts the following arguments:

	_addr_	The address at which the *MemFramer* will be installed
	_end_	The address marking the end of the region of usable memory that has to be managed
	_blksz_	The size of each individual frame

## Allocating

Allocation can be done using *mem_framer_alloc()*. This method is the implementation of mem_alloc(9) for a *MemFramer*.

Note: allocating more than the frame size leads to an allocation failure.

## Freeing

Freeing of a frame can be done using *mem_framer_free()*. Refer to mem_free(9) for the documentation.

# CODE REFERENCES

The *MemFramer* allocator and its related functions are defined in _mem/framer.c_.

# SEE ALSO

memallocator(9)