blob: 6d7034bca0b5e619022db513aebd3ddee0a93632 (
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
|
#ifndef MEM_FRAMER_H
#define MEM_FRAMER_H
#include <rt.h>
#include "allocator.h"
typedef struct mem_framer_freed {
struct mem_framer_freed *next;
} MemFramerFreed;
/* Allocator for frames: aligned regions of memory of same size */
typedef struct mem_framer {
MemAllocator allocator;
/* The next frame to be given off to the caller
in case the freelist is empty */
usize next;
/* The end of the region covered by the memory allocator */
usize end;
/* The address of the last frame that has been added in
the freelist
NOTE: the freelist is a singly-linked list comprising
all frames that have been previously allocated
and then freed */
MemFramerFreed *free;
/* The size of a frame. This value also defines the alignment
that the frames must respect */
uint blksz;
} 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);
#endif
|