OpenTTD Source: ScriptAllocator Struct Reference

OpenTTD Source 15.0-RC2

Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
ScriptAllocator Struct Reference

## Public Member Functions
size_t | GetAllocatedSize () const
void | CheckLimit () const
void | Reset ()
void * | Malloc (SQUnsignedInteger size)
void * | Realloc (void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size)
void | Free (void *p, SQUnsignedInteger size)

## Private Member Functions
void | CheckAllocationAllowed (size_t requested_size)
| Checks whether an allocation is allowed by the memory limit set for the script.
void * | DoAlloc (SQUnsignedInteger requested_size)
| Internal helper to allocate the given amount of bytes.

## Private Attributes
std::allocator< uint8_t > | allocator
size_t | allocated_size = 0
| Sum of allocated data size.
size_t | allocation_limit
| Maximum this allocator may use before allocations fail.
bool | error_thrown = false
| Whether the error has already been thrown, so to not throw secondary errors in the handling of the allocation error.

## Static Private Attributes
static const size_t | SAFE_LIMIT = 0x8000000
| 128 MiB, a safe choice for almost any situation

## Detailed Description

Definition at line 32 of file squirrel.cpp.

## Constructor & Destructor Documentation

## ◆ ScriptAllocator()

ScriptAllocator::ScriptAllocator | ( |  | ) |
| inline

Definition at line 155 of file squirrel.cpp.

## ◆ ~ScriptAllocator()

ScriptAllocator::~ScriptAllocator | ( |  | ) |
| inline

Definition at line 161 of file squirrel.cpp.

## Member Function Documentation

## ◆ CheckAllocationAllowed()

void ScriptAllocator::CheckAllocationAllowed | ( | size_t | requested_size | ) |
| inlineprivate

Checks whether an allocation is allowed by the memory limit set for the script.

Parameters

  requested_size | The requested size that was requested to be allocated.

Exceptions

  Script_FatalError | When memory may not be allocated (limit reached, except for error handling).

Definition at line 56 of file squirrel.cpp.

References allocation_limit.

## ◆ CheckLimit()

void ScriptAllocator::CheckLimit | ( |  | ) | const
| inline

Definition at line 107 of file squirrel.cpp.

## ◆ DoAlloc()

void * ScriptAllocator::DoAlloc | ( | SQUnsignedInteger | requested_size | ) |
| inlineprivate

Internal helper to allocate the given amount of bytes.

Parameters

  requested_size | The requested size.

Returns
  The allocated memory.

Exceptions

  Script_FatalError | When memory could not be allocated.

Definition at line 76 of file squirrel.cpp.

## ◆ Free()

void ScriptAllocator::Free | ( | void * | p,
|  | SQUnsignedInteger | size
| ) |  |
| inline

Definition at line 143 of file squirrel.cpp.

## ◆ GetAllocatedSize()

size_t ScriptAllocator::GetAllocatedSize | ( |  | ) | const
| inline

Definition at line 105 of file squirrel.cpp.

## ◆ Malloc()

void * ScriptAllocator::Malloc | ( | SQUnsignedInteger | size | ) |
| inline

Definition at line 118 of file squirrel.cpp.

## ◆ Realloc()

void * ScriptAllocator::Realloc | ( | void * | p,
|  | SQUnsignedInteger | oldsize,
|  | SQUnsignedInteger | size
| ) |  |
| inline

Definition at line 124 of file squirrel.cpp.

## ◆ Reset()

void ScriptAllocator::Reset | ( |  | ) |
| inline

Definition at line 112 of file squirrel.cpp.

## Field Documentation

## ◆ allocated_size

size_t ScriptAllocator::allocated_size = 0
| private

Sum of allocated data size.

Definition at line 35 of file squirrel.cpp.

## ◆ allocation_limit

size_t ScriptAllocator::allocation_limit
| private

Maximum this allocator may use before allocations fail.

Definition at line 36 of file squirrel.cpp.

Referenced by CheckAllocationAllowed().

## ◆ allocator

std::allocator<uint8_t> ScriptAllocator::allocator
| private

Definition at line 34 of file squirrel.cpp.

## ◆ error_thrown

bool ScriptAllocator::error_thrown = false
| private

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 43 of file squirrel.cpp.

## ◆ SAFE_LIMIT

const size_t ScriptAllocator::SAFE_LIMIT = 0x8000000
| staticprivate

128 MiB, a safe choice for almost any situation

Definition at line 45 of file squirrel.cpp.

The documentation for this struct was generated from the following file:

- src/script/squirrel.cpp