Hey guys,
I have been learning to program in C for the past few years and always used Casey’s approach to memory management - allocate a big memory “pool” at start and use memory arenas with PushSizes and stuff - also I use his scheme for temporary memory (I haven’t gone too far in the series yet so I just use basic push only scheme that Casey uses at start).
In between experimentations something has often come up - memory gets corrupted somehow - usually involving a linked list of some sort.
1
2
3
4
5
6
7
8
9
10
11
12 | typedef struct node
{
int Value;
struct node *Next;
} node;
typedef struct list
{
node *Head;
} list;
|
With list being stored at a fixed size memory arena, I don’t quite understand how that works - it seems to me that node would grow recursively - since every node has a pointer to another node inside it.
Does that “recursive nature” of it mean you can’t actually put the “Next” pointer in any place other than the end of the struct? I recall Casey said something about this at the very start of the series - but I’m not sure this is what he was referring to.
| typedef struct world
{
list *MyList;
int MoreStuff;
// …
} world;
|
List stored in a struct with more stuff after it - that’s when memory gets corrupted?