diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index a3b584e52f..25769d7246 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -30,6 +30,8 @@ */ struct ScriptAllocator { + friend class Squirrel; + private: std::allocator 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; +} diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp index 142b19bee4..6ddf2cb200 100644 --- a/src/script/squirrel.hpp +++ b/src/script/squirrel.hpp @@ -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); };