blob: 7dd15ebc7bff36f79636330b359125f48697a0a6 (
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
|
#include "dynamic-array.hpp"
void DynArrayReserve(DynArrayBase *arr, int64_t count) {
assert(count != 0);
if (arr->reservedCount >= count) return;
char *a = nullptr;
a = Pke_New<char>(arr->elementSize * count, arr->bkt);
if (arr->ptr != nullptr) {
std::memcpy(a, arr->ptr, arr->elementSize * arr->reservedCount);
Pke_Delete<char>(arr->ptr, arr->elementSize * arr->reservedCount, arr->bkt);
}
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->bkt);
arr->ptr = CAFE_BABE(char);
}
|