-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_alloc.h
More file actions
executable file
·49 lines (39 loc) · 1.1 KB
/
virtual_alloc.h
File metadata and controls
executable file
·49 lines (39 loc) · 1.1 KB
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
#ifndef VIRTUAL_ALLOC_H
#define VIRTUAL_ALLOC_H
#include <stddef.h>
#include <stdint.h>
#include <string.h>
void init_allocator(void * heapstart, uint8_t initial_size, uint8_t min_size);
void * virtual_malloc(void * heapstart, uint32_t size);
int virtual_free(void * heapstart, void * ptr);
void * virtual_realloc(void * heapstart, void * ptr, uint32_t size);
void virtual_info(void * heapstart);
uint64_t pow_2(uint64_t x)
{
return (1 << x);
}
struct Block{
//Size of block
uint64_t size;
//Whether the block is allocated or not. 0 = free to allocate, 1 = already allocated
char status;
//Left block buddy
struct Block* left;
//Right block buddy
struct Block* right;
//Address of the block on the virtual heap
void* block_address;
};
struct virtual_heap{
//Size of the virtual heap
int64_t size;
//Min size for splitting
int64_t min_size;
//Pointer to the first block on the actual heap
struct Block* startBlock;
//Total number of blocks
int64_t block_Count;
//Total number of spare blocks after merge
int64_t spare_Count;
};
#endif