-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathValueAllocator.cpp
More file actions
47 lines (31 loc) · 1.01 KB
/
ValueAllocator.cpp
File metadata and controls
47 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*=====================================================================
ValueAllocator.cpp
------------------
Copyright Glare Technologies Limited 2025 -
=====================================================================*/
#include "ValueAllocator.h"
#include "Value.h"
namespace Winter
{
ValueAllocator::ValueAllocator()
: float_allocator(/*ob alloc size=*/sizeof(Winter::FloatValue), 16, /*block capacity=*/64)
{
}
FloatValue* ValueAllocator::allocFloatValue(float v)
{
glare::FastPoolAllocator::AllocResult alloc_res = float_allocator.alloc();
Winter::FloatValue* val = new(alloc_res.ptr) FloatValue(v); // placement new
val->value_allocator = this;
val->allocation_index = alloc_res.index;
return val;
}
void ValueAllocator::freeFloatValue(FloatValue* value)
{
assert(value->value_allocator == this);
const int idx = value->allocation_index;
// destroy object
value->~FloatValue();
// Free mem
float_allocator.free(idx);
}
} // end namespace Winter