That would work, but giving each type its own arena has advantages, for example you can instantly find out the memory usage for a given subsystem (path finding, action queues, etc) by looking at how much of the arena has been used. It also promotes cache locality, which for linked lists may not be a huge concern, but outside HMH you see arenas most often in cases where it is important.
I don't know if you're caught up on HMH but in the next few episodes Casey is going to address this exact problem, but for memory for particle systems rather than pathfinding nodes
edit: I believe ratchetfreak is suggesting something like
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 | struct FooNode
{
i32 data[4];
};
struct BarNode
{
f32 data[4];
};
struct BazNode
{
i32 data[8];
};
struct Node_16
{
union
{
FooNode foo;
BarNode bar;
u8 reserved[16];
};
Node_16 *next, *prev;
};
static_assert(sizeof(Node_16) == sizeof(Node_16*)*2 + 16);
struct Node_32
{
union
{
BazNode baz;
u8 reserved[32];
};
Node_32 *next, *prev;
};
static_assert(sizeof(Node_32) == sizeof(Node_32*)*2 + 32);
|
And any node type that fits in Node_16 can go in a Node_16 arena, and for larger nodes, a Node_32 arena, and so on. I didn't add a type field to make it a tagged union because the calling code would know, presumably.