-
Notifications
You must be signed in to change notification settings - Fork 0
/
Memory.cpp
68 lines (48 loc) · 1.41 KB
/
Memory.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "Memory.h"
#include "LinkedList.h"
#include "Strings.h"
#include <stdlib.h>
#ifdef NDEBUG
void* Memory_Allocate(uint64 size) {
return malloc(size);
}
void* Memory_Reallocate(void* block, uint64 size) {
return realloc(block, size);
}
#else
LinkedList* allocations;
static boolean allocationsInitialized = false;
//add a record of the allocation to allocations and remove it on FreeD()
void* Memory_AllocateD(uint64 size, uint64 line, int8* file) {
/*if (!allocationsInitialized) allocations = LinkedList_New( ( void(*)(void*) ) String_Free);*/
return malloc(size);
}
void* Memory_ReallocateD(void* block, uint64 size, uint64 line, int8* file) {
/*if (!allocationsInitialized) allocations = LinkedList_New( ( void(*)(void*) ) String_Free);*/
return realloc(block, size);
}
#endif
void Memory_Free(void* block) {
#ifdef NDEBUG
free(block);
#else
free(block);
#endif
}
void Memory_BlockCopy(uint8* source, uint8* destination, uint64 amount) {
uint8 i;
if (amount > 0) {
for (; amount >= 8; amount -= 8)
*(uint64*)(destination + amount - 8) = *(uint64*)(source + amount - 8);
for (i = 0; i < amount; i++)
*(uint8*)(destination + i) = *(source + i);
}
}
boolean Memory_Compare(uint8* blockA, uint8* blockB, uint64 lengthA, uint64 lengthB) {
if (lengthA != lengthB)
return false;
for (; lengthA > 0; lengthA--)
if (blockA[lengthA - 1] != blockB[lengthA - 1])
return false;
return true;
}