allocation will realloc if necessary. the buffer will be zeroed whether reallocated or not
| 38 | // the buffer will be zeroed whether reallocated or not |
| 39 | // |
| 40 | void allocate(int n) |
| 41 | { |
| 42 | const uintptr_t alignment = 0x10; |
| 43 | const uintptr_t mask = ~0xf; |
| 44 | size_t initialSize = sizeof(T) * n + alignment; |
| 45 | if (_size != n) { |
| 46 | if (_allocation) |
| 47 | free(_allocation); |
| 48 | |
| 49 | if (n) { |
| 50 | _allocation = static_cast<T*>(calloc(initialSize, 1)); |
| 51 | _data = (T*)((((intptr_t)_allocation) + (alignment-1)) & mask); |
| 52 | } |
| 53 | else { |
| 54 | _allocation = nullptr; |
| 55 | _data = nullptr; |
| 56 | } |
| 57 | |
| 58 | _size = n; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | T * data() { return _data; } |
| 63 | const T * data() const { return _data; } |
no outgoing calls
no test coverage detected