12 #ifndef ALLOC_TYPE_HPP 13 #define ALLOC_TYPE_HPP 26 template <
typename T,
size_t length>
107 T *Allocate(
size_t count)
109 if (this->count < count) {
111 this->buffer = MallocT<T>(count);
124 T *ZeroAllocate(
size_t count)
126 if (this->count < count) {
128 this->buffer = CallocT<T>(count);
131 memset(this->buffer, 0,
sizeof(T) * count);
140 inline const T *GetBuffer()
const 161 inline void *
operator new(
size_t size) {
return CallocT<byte>(size); }
168 inline void *
operator new[](
size_t size) {
return CallocT<byte>(size); }
174 inline void operator delete(
void *ptr) {
free(ptr); }
180 inline void operator delete[](
void *ptr) {
free(ptr); }
187 template <
typename T>
212 inline operator T *() {
return this->ptr; }
214 inline operator const T *()
const {
return this->ptr; }
T * operator->()
Gets a pointer to the data stored in this wrapper.
T * EndOf()
Gets a pointer to the last data element stored in this wrapper.
Functions related to the allocation of memory.
static T * MallocT(size_t num_elements)
Simplified allocation function that allocates the specified number of elements of the given type...
A small 'wrapper' for allocations that can be done on most OSes on the stack, but are just too large ...
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that ver...
A smart pointer class that free()'s the pointer on destruction.
Base class that provides memory initialization on dynamically created objects.
T data[length]
Storing the data on the stack.
size_t count
Number of T elements in the buffer.
ReusableBuffer()
Create a new buffer.
#define endof(x)
Get the end element of an fixed size array.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
void Assign(T *ptr)
Take ownership of a new pointer and free the old one if needed.
~ReusableBuffer()
Clear the buffer.