Functions related to the allocation of memory. More...
Go to the source code of this file.
Defines | |
| #define | AllocaM(T, num_elements) |
| alloca() has to be called in the parent function, so define AllocaM() as a macro | |
Functions | |
| void NORETURN | MallocError (size_t size) |
| Function to exit with an error message after malloc() or calloc() have failed. | |
| void NORETURN | ReallocError (size_t size) |
| Function to exit with an error message after realloc() have failed. | |
| static void | CheckAllocationConstraints (size_t element_size, size_t num_elements) |
| Checks whether allocating memory would overflow size_t. | |
| template<typename T > | |
| static void | CheckAllocationConstraints (size_t num_elements) |
| Checks whether allocating memory would overflow size_t. | |
| template<typename T > | |
| static T * | MallocT (size_t num_elements) |
| Simplified allocation function that allocates the specified number of elements of the given type. | |
| template<typename T > | |
| static T * | CallocT (size_t num_elements) |
| Simplified allocation function that allocates the specified number of elements of the given type. | |
| template<typename T > | |
| static T * | ReallocT (T *t_ptr, size_t num_elements) |
| Simplified reallocation function that allocates the specified number of elements of the given type. | |
Functions related to the allocation of memory.
Definition in file alloc_func.hpp.
| #define AllocaM | ( | T, | ||
| num_elements | ||||
| ) |
(CheckAllocationConstraints<T>(num_elements), \ (T*)alloca((num_elements) * sizeof(T)))
alloca() has to be called in the parent function, so define AllocaM() as a macro
Definition at line 134 of file alloc_func.hpp.
Referenced by CmdBuildRailStation(), CmdBuildRailWaypoint(), TimetableWindow::DrawWidget(), FinalisePriceBaseMultipliers(), GenerateTownNameString(), LoadNewGRFSound(), CrashLogWindows::LogModules(), MakeBMPImage(), NetworkHTTPSocketHandler::NetworkHTTPSocketHandler(), ReadRecolourSprite(), ReadSpriteLayout(), and LanguageWriter::WriteLang().
| static T* CallocT | ( | size_t | num_elements | ) | [inline, static] |
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 87 of file alloc_func.hpp.
References MallocError().
| static void CheckAllocationConstraints | ( | size_t | num_elements | ) | [inline, static] |
Checks whether allocating memory would overflow size_t.
| T | Structure to allocate. |
| num_elements | Number of elements to allocate. |
Definition at line 43 of file alloc_func.hpp.
References CheckAllocationConstraints().
| static void CheckAllocationConstraints | ( | size_t | element_size, | |
| size_t | num_elements | |||
| ) | [inline, static] |
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 31 of file alloc_func.hpp.
References MallocError().
Referenced by CheckAllocationConstraints(), and Hash::Init().
| void NORETURN 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 18 of file alloc_func.cpp.
References error().
Referenced by CallocT(), CheckAllocationConstraints(), and MallocT().
| static T* MallocT | ( | size_t | num_elements | ) | [inline, static] |
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 59 of file alloc_func.hpp.
References MallocError().
| void NORETURN 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 27 of file alloc_func.cpp.
References error().
Referenced by ReallocT().
| static T* ReallocT | ( | T * | t_ptr, | |
| size_t | num_elements | |||
| ) | [inline, static] |
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 113 of file alloc_func.hpp.
References free(), and ReallocError().
Referenced by AllocateSpecToStation(), SmallVector< RefitOption, 32 >::Append(), SmallVector< RefitOption, 32 >::Compact(), DeallocateSpecFromStation(), DEFINE_NEWGRF_CLASS_METHOD(), GamelogChange(), GetNewEngine(), IniLoadFile::LoadFromDisk(), TextfileWindow::LoadTextfile(), NetworkInitChatMessage(), NetworkReInitChatBoxSize(), SquirrelStd::require(), NetworkTCPSocketHandler::SendPacket(), StationChangeInfo(), and TranslateTTDPatchCodes().
1.7.1