mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-21 03:12:41 +01:00
Codechange: [Script] Add helpers for script memory allocation accounting
This commit is contained in:
committed by
Peter Nelson
parent
ed687c6e10
commit
33c967a558
@@ -30,6 +30,8 @@
|
||||
*/
|
||||
|
||||
struct ScriptAllocator {
|
||||
friend class Squirrel;
|
||||
|
||||
private:
|
||||
std::allocator<uint8_t> allocator;
|
||||
size_t allocated_size = 0; ///< Sum of allocated data size
|
||||
@@ -814,3 +816,14 @@ SQInteger Squirrel::GetOpsTillSuspend()
|
||||
{
|
||||
return this->vm->_ops_till_suspend;
|
||||
}
|
||||
|
||||
void Squirrel::IncreaseAllocatedSize(size_t bytes)
|
||||
{
|
||||
_squirrel_allocator->CheckAllocationAllowed(bytes);
|
||||
_squirrel_allocator->allocated_size += bytes;
|
||||
}
|
||||
|
||||
void Squirrel::DecreaseAllocatedSize(size_t bytes)
|
||||
{
|
||||
_squirrel_allocator->allocated_size -= bytes;
|
||||
}
|
||||
|
||||
@@ -291,6 +291,18 @@ public:
|
||||
* Get number of bytes allocated by this VM.
|
||||
*/
|
||||
size_t GetAllocatedMemory() const noexcept;
|
||||
|
||||
/**
|
||||
* Increase number of bytes allocated in the current script allocator scope.
|
||||
* @param bytes Number of bytes to increase.
|
||||
*/
|
||||
static void IncreaseAllocatedSize(size_t bytes);
|
||||
|
||||
/**
|
||||
* Decrease number of bytes allocated in the current script allocator scope.
|
||||
* @param bytes Number of bytes to decrease.
|
||||
*/
|
||||
static void DecreaseAllocatedSize(size_t bytes);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user