blob: ed181f7e5b0278aa8db0039085f808d5d17a8635 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "dynamic-array.hpp"
void DynArrayReserve(DynArrayBase *arr, int64_t count) {
assert(count != 0);
if (arr->reservedCount >= count) return;
char *a = Pke_New<char>(arr->elementSize * count);
if (arr->ptr != nullptr) {
std::memcpy(a, arr->ptr, arr->elementSize * arr->reservedCount);
Pke_Delete<char>(arr->ptr, arr->elementSize * arr->reservedCount);
}
arr->reservedCount = count;
arr->ptr = a;
}
void DynArrayDestroy(DynArrayBase *arr) {
if (arr->ptr == nullptr) return;
if (arr->ptr == CAFE_BABE(char)) return;
if (arr->reservedCount > 0)
Pke_Delete<char>(arr->ptr, arr->elementSize * arr->reservedCount);
arr->ptr = CAFE_BABE(char);
}
|