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...
|
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.
|
|
void * | Malloc (SQUnsignedInteger size) |
|
void * | Realloc (void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size) |
|
void | Free (void *p, SQUnsignedInteger size) |
|
|
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.
|
|
|
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.
◆ ScriptAllocator()
ScriptAllocator::ScriptAllocator |
( |
| ) |
|
|
inline |
◆ ~ScriptAllocator()
ScriptAllocator::~ScriptAllocator |
( |
| ) |
|
|
inline |
◆ CheckAllocation()
void ScriptAllocator::CheckAllocation |
( |
size_t |
requested_size, |
|
|
void * |
p |
|
) |
| |
|
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.
- Parameters
-
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().
◆ CheckLimit()
void ScriptAllocator::CheckLimit |
( |
| ) |
const |
|
inline |
◆ Free()
void ScriptAllocator::Free |
( |
void * |
p, |
|
|
SQUnsignedInteger |
size |
|
) |
| |
|
inline |
◆ Malloc()
void * ScriptAllocator::Malloc |
( |
SQUnsignedInteger |
size | ) |
|
|
inline |
◆ Realloc()
void * ScriptAllocator::Realloc |
( |
void * |
p, |
|
|
SQUnsignedInteger |
oldsize, |
|
|
SQUnsignedInteger |
size |
|
) |
| |
|
inline |
◆ allocated_size
size_t ScriptAllocator::allocated_size |
Sum of allocated data size.
Definition at line 37 of file squirrel.cpp.
◆ allocation_limit
size_t ScriptAllocator::allocation_limit |
Maximum this allocator may use before allocations fail.
Definition at line 38 of file squirrel.cpp.
◆ error_thrown
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.
◆ SAFE_LIMIT
const size_t ScriptAllocator::SAFE_LIMIT = 0x8000000 |
|
static |
128 MiB, a safe choice for almost any situation
Definition at line 47 of file squirrel.cpp.
The documentation for this struct was generated from the following file: