OpenTTD Source
20241121-master-g67a0fccfad
|
Functions related to the allocation of memory. More...
Go to the source code of this file.
Functions | |
void | MallocError (size_t size) |
Function to exit with an error message after malloc() or calloc() have failed. More... | |
void | ReallocError (size_t size) |
Function to exit with an error message after realloc() have failed. More... | |
void | CheckAllocationConstraints (size_t element_size, size_t num_elements) |
Checks whether allocating memory would overflow size_t. More... | |
template<typename T > | |
void | CheckAllocationConstraints (size_t num_elements) |
Checks whether allocating memory would overflow size_t. More... | |
template<typename T > | |
T * | MallocT (size_t num_elements) |
Simplified allocation function that allocates the specified number of elements of the given type. More... | |
template<typename T > | |
T * | CallocT (size_t num_elements) |
Simplified allocation function that allocates the specified number of elements of the given type. More... | |
template<typename T > | |
T * | ReallocT (T *t_ptr, size_t num_elements) |
Simplified reallocation function that allocates the specified number of elements of the given type. More... | |
Functions related to the allocation of memory.
Definition in file alloc_func.hpp.
|
inline |
Simplified allocation function that allocates the specified number of elements of the given type.
It also explicitly casts it to the requested type.
T | the type of the variable(s) to allocation. |
num_elements | the number of elements to allocate of the given type. |
Definition at line 85 of file alloc_func.hpp.
|
inline |
Checks whether allocating memory would overflow size_t.
element_size | Size of the structure to allocate. |
num_elements | Number of elements to allocate. |
Definition at line 29 of file alloc_func.hpp.
References MallocError().
Referenced by CheckAllocationConstraints().
|
inline |
Checks whether allocating memory would overflow size_t.
T | Structure to allocate. |
num_elements | Number of elements to allocate. |
Definition at line 41 of file alloc_func.hpp.
References CheckAllocationConstraints().
void MallocError | ( | size_t | size | ) |
Function to exit with an error message after malloc() or calloc() have failed.
size | number of bytes we tried to allocate |
Definition at line 20 of file alloc_func.cpp.
Referenced by ScriptAllocator::CheckAllocation(), and CheckAllocationConstraints().
|
inline |
Simplified allocation function that allocates the specified number of elements of the given type.
It also explicitly casts it to the requested type.
T | the type of the variable(s) to allocation. |
num_elements | the number of elements to allocate of the given type. |
Definition at line 57 of file alloc_func.hpp.
void ReallocError | ( | size_t | size | ) |
Function to exit with an error message after realloc() have failed.
size | number of bytes we tried to allocate |
Definition at line 29 of file alloc_func.cpp.
|
inline |
Simplified reallocation function that allocates the specified number of elements of the given type.
It also explicitly casts it to the requested type. It extends/shrinks the memory allocation given in t_ptr.
T | the type of the variable(s) to allocation. |
t_ptr | the previous allocation to extend/shrink. |
num_elements | the number of elements to allocate of the given type. |
Definition at line 111 of file alloc_func.hpp.
Referenced by DEFINE_POOL_METHOD().