blob: 06b79c247134ee2905391dc26e32e9da028d2ccd (
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
25
26
27
28
|
#ifndef ARRAY_CC
#define ARRAY_CC
#include "memory.cc"
#define ARRAY_INIT 4
#define ARRAY_GROWTH 2
template <typename T>
struct Array {
Slice<T> buffer;
const Allocator* allocator;
};
#define array_init(T, allocator) \
Array<T> { Slice<T>{}, allocator }
template <typename T>
void array_deinit(Array<T>* array) {
assert(array != nullptr);
if (unlikely(array->allocator == nullptr)) return;
slice_deallocate(array->allocator, &array->buffer);
array->allocator = nullptr;
}
#endif
|