OpenTTD Source  20241120-master-g6d3adc6169
pool_func.hpp File Reference

Some methods of Pool are placed here in order to reduce compilation time and binary size. More...

#include "alloc_func.hpp"
#include "bitmath_func.hpp"
#include "mem_func.hpp"
#include "pool_type.hpp"
#include "../error_func.h"
#include "../saveload/saveload_error.hpp"

Go to the source code of this file.

Macros

#define DEFINE_POOL_METHOD(type)
 Helper for defining the method's signature. More...
 
#define INSTANTIATE_POOL_METHODS(name)
 Force instantiation of pool methods so we don't get linker errors. More...
 

Functions

 DEFINE_POOL_METHOD (inline)
 Create a clean pool. More...
 
 DEFINE_POOL_METHOD (inline void)
 Resizes the pool so 'index' can be addressed. More...
 
 DEFINE_POOL_METHOD (inline void *)
 Makes given index valid. More...
 
 DEFINE_POOL_METHOD (void *)
 Allocates new item. More...
 
 DEFINE_POOL_METHOD (void)
 Deallocates memory used by this index and marks item as free. More...
 

Detailed Description

Some methods of Pool are placed here in order to reduce compilation time and binary size.

Definition in file pool_func.hpp.

Macro Definition Documentation

◆ DEFINE_POOL_METHOD

#define DEFINE_POOL_METHOD (   type)
Value:
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type, bool Tcache, bool Tzero> \
Base class for all pools.
Definition: pool_type.hpp:80

Helper for defining the method's signature.

Parameters
typeThe return type of the method.

Definition at line 25 of file pool_func.hpp.

◆ INSTANTIATE_POOL_METHODS

#define INSTANTIATE_POOL_METHODS (   name)
Value:
template void * name ## Pool::GetNew(size_t size); \
template void * name ## Pool::GetNew(size_t size, size_t index); \
template void name ## Pool::FreeItem(size_t index); \
template void name ## Pool::CleanPool();
void CleanPool() override
Virtual method that deletes all items in the pool.

Force instantiation of pool methods so we don't get linker errors.

Only methods accessed from methods defined in pool.hpp need to be forcefully instantiated.

Definition at line 237 of file pool_func.hpp.

Function Documentation

◆ DEFINE_POOL_METHOD() [1/5]

DEFINE_POOL_METHOD ( inline void *  )

Makes given index valid.

Parameters
sizesize of item
indexindex of item
Precondition
index < this->size
this->Get(index) == nullptr

Definition at line 108 of file pool_func.hpp.

References SetBit().

◆ DEFINE_POOL_METHOD() [2/5]

DEFINE_POOL_METHOD ( inline void  )

Resizes the pool so 'index' can be addressed.

Parameters
indexindex we will allocate later
Precondition
index >= this->size
index < Tmax_size

Definition at line 54 of file pool_func.hpp.

References Align(), MemSetT(), and ReallocT().

◆ DEFINE_POOL_METHOD() [3/5]

DEFINE_POOL_METHOD ( inline  size_t)

Create a clean pool.

Searches for first free index.

Parameters
nameThe name for the pool.
Returns
first free index, NO_FREE_ITEM on failure

Definition at line 33 of file pool_func.hpp.

◆ DEFINE_POOL_METHOD() [4/5]

DEFINE_POOL_METHOD ( void *  )

Allocates new item.

Allocates new item with given index.

Parameters
sizesize of item
Returns
pointer to allocated item
Note
FatalError() on failure! (no free item)
Parameters
sizesize of item
indexindex of item
Returns
pointer to allocated item
Note
SlErrorCorruptFmt() on failure! (index out of range or already used)

Definition at line 142 of file pool_func.hpp.

◆ DEFINE_POOL_METHOD() [5/5]

DEFINE_POOL_METHOD ( void  )

Deallocates memory used by this index and marks item as free.

Destroys all items in the pool and resets all member variables.

Parameters
indexitem to deallocate
Precondition
unit is allocated (non-nullptr)
Note
'delete nullptr' doesn't cause call of this function, so it is safe

Definition at line 186 of file pool_func.hpp.

References ClrBit(), and free().