blob: f65688c3a45e81b8132d7889def83ffcf3bc73ba (
plain)
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
|
Placement allocation / specifying an allocator
==============================================
When using arena allocation, and also to make things more efficient,
one will often want to use custom allocation when creating a new object.
So when a function directly or indirectly creates something that would
be allocated on the heap, we need to have a parameter (or a thread-local
variable) to specify the allocator.
(Also, there may be some cases where you want to always use the heap,
such as for lazy initialization and libraries that do built-in caching
etc.)
The allocator needs to contain this info at least:
- Type of allocator
- Allocator specific data, e.g. pointer to allocation area
type Allocator = case struct (
.Heap ( )
# FIXME it is probably better to return a non-pointer struct value in this case? (i.e. stack return)
#.MergedImplicitSize (
# []byte data
#)
.MergedFixedSize (
size len
[len]byte data
)
.FixedSize (
size len
rwref [len]byte data
)
.Arena (
rwref Arena arena
)
# if we alloc function pointers
.CustomAllocator (
)
)
|