OpenTTD Source 20241224-master-gf74b0cf984
|
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that very often, or for places where static memory is allocated that might need to be reallocated sometimes. More...
#include <alloc_type.hpp>
Public Member Functions | |
ReusableBuffer () | |
Create a new buffer. | |
~ReusableBuffer () | |
Clear the buffer. | |
T * | Allocate (size_t count) |
Get buffer of at least count times T. | |
T * | ZeroAllocate (size_t count) |
Get buffer of at least count times T with zeroed memory. | |
const T * | GetBuffer () const |
Get the currently allocated buffer. | |
Private Attributes | |
T * | buffer |
The real data buffer. | |
size_t | count |
Number of T elements in the buffer. | |
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that very often, or for places where static memory is allocated that might need to be reallocated sometimes.
Every time Allocate or ZeroAllocate is called previous results of both functions will become invalid.
Definition at line 24 of file alloc_type.hpp.
|
inline |
Create a new buffer.
Definition at line 31 of file alloc_type.hpp.
|
inline |
|
inline |
Get buffer of at least count times T.
count | the minimum buffer size |
Definition at line 42 of file alloc_type.hpp.
References ReusableBuffer< T >::buffer, ReusableBuffer< T >::count, and free().
Referenced by Blitter_8bppOptimized::Encode(), LoadNewGRFFileFromFile(), NetworkDrawChatMessage(), and OpenGLSprite::Update().
|
inline |
Get the currently allocated buffer.
Definition at line 75 of file alloc_type.hpp.
References ReusableBuffer< T >::buffer.
Referenced by NetworkUndrawChatMessage(), and OpenGLSprite::Update().
|
inline |
Get buffer of at least count times T with zeroed memory.
count | the minimum buffer size |
Definition at line 59 of file alloc_type.hpp.
References ReusableBuffer< T >::buffer, ReusableBuffer< T >::count, and free().
|
private |
The real data buffer.
Definition at line 26 of file alloc_type.hpp.
Referenced by ReusableBuffer< T >::Allocate(), ReusableBuffer< T >::GetBuffer(), and ReusableBuffer< T >::ZeroAllocate().
|
private |
Number of T elements in the buffer.
Definition at line 27 of file alloc_type.hpp.
Referenced by ReusableBuffer< T >::Allocate(), and ReusableBuffer< T >::ZeroAllocate().