OpenTTD Source: ReusableBuffer< T > Class Template Reference

OpenTTD Source 12.2

Public Member Functions | Private Attributes
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
| ReusableBuffer ()
| Create a new buffer.
| ~ReusableBuffer ()
| Clear the buffer.
T * | Allocate (size_t count)
| Get buffer of at least count times T. More...
T * | ZeroAllocate (size_t count)
| Get buffer of at least count times T with zeroed memory. More...
const T * | GetBuffer () const
| Get the currently allocated buffer. More...

## Private Attributes
T * | buffer
| The real data buffer.
size_t | count
| Number of T elements in the 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 24 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

  count | the minimum buffer size

Returns
  the buffer

Definition at line 42 of file alloc_type.hpp.

Referenced by OpenGLSprite::Update().

## ◆ GetBuffer()

template<typename T >

const T* ReusableBuffer< T >::GetBuffer | ( |  | ) | const
| inline

Get the currently allocated buffer.

Returns
  the buffer

Definition at line 75 of file alloc_type.hpp.

## ◆ ZeroAllocate()

template<typename T >

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

Get buffer of at least count times T with zeroed memory.

Note
  the buffer might be bigger
  calling this function invalidates any previous buffers given

Parameters

  count | the minimum buffer size

Returns
  the buffer

Definition at line 59 of file alloc_type.hpp.

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

- src/core/alloc_type.hpp