blob: e67c0c18f5805fc46c34d9b748c276be983f923b (
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
|
"Inverse allocator"
===================
Combine an arena allocator with an ability to mark objects as discarded.
This requires that the size of the objects is known at the time when they
are free'd (but this should always be known anyway, otherwise e.g. arrays
can't be used safely).
The "inverse" part comes from it having trivial allocation but complex
de-allocation (all de-allocations need to be tracked).
Advantages:
1. Can detect when discarded data is accessed, together with either
some lifetime checker or something like Valgrind.
(Unlike in an ordinary arena allocator).
2. Still very fast allocation, at least until something is free'd.
Disadvantages:
(if the memory is actually released, it could also simply be blocked, in
which case none of these really apply)
1. Needs to know the lifetime of objects and when it's safe to free them.
2. Allocation after a free() is slower compared to a plain arena allocator.
3. More complex than an arena allocator.
|