Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Ast/include/Luau/Allocator.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "Luau/Ast.h"
5
#include "Luau/Location.h"
6
#include "Luau/DenseHash.h"
7
#include "Luau/Common.h"
8
9
#include <vector>
10
11
namespace Luau
12
{
13
14
class Allocator
15
{
16
public:
17
Allocator();
18
Allocator(Allocator&&);
19
20
Allocator& operator=(Allocator&&) = delete;
21
22
~Allocator();
23
24
void* allocate(size_t size);
25
26
template<typename T, typename... Args>
27
T* alloc(Args&&... args)
28
{
29
static_assert(std::is_trivially_destructible<T>::value, "Objects allocated with this allocator will never have their destructors run!");
30
31
T* t = static_cast<T*>(allocate(sizeof(T)));
32
new (t) T(std::forward<Args>(args)...);
33
return t;
34
}
35
36
private:
37
struct Page
38
{
39
Page* next;
40
41
alignas(8) char data[8192];
42
};
43
44
Page* root;
45
size_t offset;
46
};
47
48
} // namespace Luau
49
50