Something went wrong. Try again.
Monorepo for PackTools - tooling for Minecraft Modpacks!
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738#pragma once
#include "packluau.h"
#include <cstddef>#include <limits>
namespace packluau {
/// Luau's allocator: every block of the state goes through `allocate`, which forwards to the/// host's `realloc` and refuses growth past the current limit, so a run's memory budget holds.class Allocator { public: explicit Allocator(const pl_host &host) noexcept;
/// The `lua_Alloc` entry point; `user_data` is the `Allocator`. static void *allocate(void *user_data, void *block, std::size_t old_size, std::size_t new_size) noexcept;
/// Lets the live total grow by at most `extra` bytes from now on. void limit_growth(std::size_t extra) noexcept; /// Lifts the limit; the runtime's own state is never budgeted. void unlimit() noexcept;
[[nodiscard]] bool exceeded() const noexcept { return exceeded_; } [[nodiscard]] std::size_t live() const noexcept { return live_; }
private: void *(*host_realloc_)(void *, void *, std::size_t, std::size_t); void *host_context_; std::size_t live_ = 0; std::size_t limit_ = std::numeric_limits<std::size_t>::max(); /// Sticky until `unlimit`: a script that catches the out-of-memory error still stops. bool exceeded_ = false;};
} // namespace packluau