-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathMemoryPool.cpp
52 lines (43 loc) · 1015 Bytes
/
MemoryPool.cpp
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
50
51
/**
* naken_asm assembler.
* Author: Michael Kohn
* Email: [email protected]
* Web: https://www.mikekohn.net/
* License: GPLv3
*
* Copyright 2010-2023 by Michael Kohn
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common/MemoryPool.h"
MemoryPool *memory_pool_add(NakenHeap *heap, int heap_len)
{
MemoryPool *curr_pool;
MemoryPool *memory_pool = (MemoryPool *)malloc(heap_len + sizeof(MemoryPool));
memory_pool->len = heap_len;
memory_pool->ptr = 0;
memory_pool->next = NULL;
if (heap->memory_pool == NULL)
{
heap->memory_pool = memory_pool;
}
else
{
curr_pool = heap->memory_pool;
while (curr_pool->next != NULL) { curr_pool = curr_pool->next; }
curr_pool->next = memory_pool;
}
return memory_pool;
}
void memory_pool_free(MemoryPool *memory_pool)
{
MemoryPool *curr_pool = memory_pool;
while (curr_pool != NULL)
{
MemoryPool *last_pool = curr_pool;
curr_pool = curr_pool->next;
free(last_pool);
}
}