OpenTTD Source 20250312-master-gcdcc6b491d
ReusableBuffer< T > Class Template Reference

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

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 of default initialised elements.
 
const T * GetBuffer () const
 Get the currently allocated buffer.
 

Private Attributes

std::vector< T > buffer
 

Detailed Description

template<typename T>
class ReusableBuffer< T >

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 22 of file alloc_type.hpp.

Member Function Documentation

◆ Allocate()

template<typename T >
T * ReusableBuffer< T >::Allocate ( size_t  count)
inline

Get buffer of at least count times T.

Note
the buffer might be bigger
calling this function invalidates any previous buffers given
Parameters
countthe minimum buffer size
Returns
the buffer

Definition at line 34 of file alloc_type.hpp.

Referenced by LoadNewGRFFileFromFile(), NetworkDrawChatMessage(), and OpenGLSprite::Update().

◆ GetBuffer()

template<typename T >
const T * ReusableBuffer< T >::GetBuffer ( ) const
inline

Get the currently allocated buffer.

Returns
the buffer

Definition at line 58 of file alloc_type.hpp.

Referenced by NetworkUndrawChatMessage(), and OpenGLSprite::Update().

◆ ZeroAllocate()

template<typename T >
T * ReusableBuffer< T >::ZeroAllocate ( size_t  count)
inline

Get buffer of at least count times T of default initialised elements.

Note
the buffer might be bigger
calling this function invalidates any previous buffers given
Parameters
countthe minimum buffer size
Returns
the buffer

Definition at line 47 of file alloc_type.hpp.

Referenced by SpriteLoader::Sprite::AllocateData(), and Blitter_8bppOptimized::Encode().

Field Documentation

◆ buffer

template<typename T >
std::vector<T> ReusableBuffer< T >::buffer
private

Definition at line 24 of file alloc_type.hpp.


The documentation for this class was generated from the following file: