Marco Devillers said:
Hi all, a short question.
I wrote a compiler which compiles to C and has a garbage collector
written in C. The garbage collector assumes that nodes in memory are
arrays of integers or pointers (I use the default integer of pointer
size type for that).
It would help a lot if you showed some code to make the question
more specific. �Obvious first question: �is the format of a Node
(ignoring the cases with floats, etc) like this
� �struct Node_s {
� � � union {
� � � � �some_integer_type � integers[ ELEMENTS_PER_NODE ];
� � � � �struct Node_s � � �*pointers[ ELEMENTS_PER_NODE ];
� � � } element_arrays;
� �};
Excellent! No, a node is just a series of cells, integers or pointers,
so I didn't define an explicit node type. Referring to a node is just
intptr_t* node, though there are a number of invariants. For brevity,
lets assume that the first value is always an integer and tells you a)
the size and b) whether the following bits are integers (a terminal
node) or pointers (a non-terminal). (It's more complex, stuff may mix
since it is a conservative collector, but this will do.)
So, I sometimes store floats, the bits, into the memory of a terminal
node starting with the second cell. But I would like it if people are
able to add new basic types to the language such as pairs of floats
for an OpenGL binding. So, a priori, I have no knowledge of what data
is stored in the payload of a terminal node.