OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #ifndef ALLOC_TYPE_HPP
11 #define ALLOC_TYPE_HPP
44 if (this->count <
count) {
46 this->buffer = MallocT<T>(
count);
61 if (this->count <
count) {
63 this->buffer = CallocT<T>(
count);
66 memset(this->buffer, 0,
sizeof(T) *
count);
96 inline void *
operator new(
size_t size) {
return CallocT<uint8_t>(size); }
103 inline void *
operator new[](
size_t size) {
return CallocT<uint8_t>(size); }
109 inline void operator delete(
void *ptr) {
free(ptr); }
115 inline void operator delete[](
void *ptr) {
free(ptr); }
T * buffer
The real data buffer.
~ReusableBuffer()
Clear the buffer.
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that ver...
T * Allocate(size_t count)
Get buffer of at least count times T.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
T * ZeroAllocate(size_t count)
Get buffer of at least count times T with zeroed memory.
Base class that provides memory initialization on dynamically created objects.
size_t count
Number of T elements in the buffer.
const T * GetBuffer() const
Get the currently allocated buffer.
ReusableBuffer()
Create a new buffer.