OpenTTD Source
20241108-master-g80f628063a
|
In the memory allocator for Squirrel we want to directly use malloc/realloc, so when the OS does not have enough memory the game does not go into unrecoverable error mode and kill the whole game, but rather let the AI die though then we need to circumvent MallocT/ReallocT. More...
Public Member Functions | |
void | CheckLimit () const |
void | CheckAllocation (size_t requested_size, void *p) |
Catch all validation for the allocation; did it allocate too much memory according to the allocation limit or did the allocation at the OS level maybe fail? In those error situations a Script_FatalError is thrown, but once that has been done further allocations are allowed to make it possible for Squirrel to throw the error and clean everything up. More... | |
void * | Malloc (SQUnsignedInteger size) |
void * | Realloc (void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size) |
void | Free (void *p, SQUnsignedInteger size) |
Data Fields | |
size_t | allocated_size |
Sum of allocated data size. | |
size_t | allocation_limit |
Maximum this allocator may use before allocations fail. | |
bool | error_thrown |
Whether the error has already been thrown, so to not throw secondary errors in the handling of the allocation error. More... | |
Static Public Attributes | |
static const size_t | SAFE_LIMIT = 0x8000000 |
128 MiB, a safe choice for almost any situation | |
In the memory allocator for Squirrel we want to directly use malloc/realloc, so when the OS does not have enough memory the game does not go into unrecoverable error mode and kill the whole game, but rather let the AI die though then we need to circumvent MallocT/ReallocT.
So no include "../safeguards.h" here as is required, but after the allocator's implementation.
Definition at line 36 of file squirrel.cpp.
|
inline |
Catch all validation for the allocation; did it allocate too much memory according to the allocation limit or did the allocation at the OS level maybe fail? In those error situations a Script_FatalError is thrown, but once that has been done further allocations are allowed to make it possible for Squirrel to throw the error and clean everything up.
requested_size | The requested size that was requested to be allocated. |
p | The pointer to the allocated object, or null if allocation failed. |
Definition at line 67 of file squirrel.cpp.
References free(), and MallocError().
bool ScriptAllocator::error_thrown |
Whether the error has already been thrown, so to not throw secondary errors in the handling of the allocation error.
This as the handling of the error will throw a Squirrel error so the Squirrel stack can be dumped, however that gets allocated by this allocator and then you might end up in an infinite loop.
Definition at line 45 of file squirrel.cpp.