To improve the computation speed, I need to store a large amount of data in a tree. Some nodes should contain the mean properties of the points inside and some other should not, such as the typical light node only contains the address to the child nodes and the typical regular node, the two address plus some information. I am looking for a smart way to store these two kinds of nodes in the same tree, using the least memory.
I am using c. I first built up my tree using structures (node.properties, node.Left, nodeRight, etc.), but it requires too much memory (if you're familiar with structures, you'll probably figure out why), so I have to go back to some kind of "in-line" organization of my tree, storing the address of the child nodes in the first two slots and (eventually) the rest of the info in the following slots.
So I though about two ways of doing it. One way is to predict the total number of nodes (easy) and allocate sufficient memory to store all nodes as regular nodes (2 slots for the child node addresses and 1 slot for the information). Another way of doing it is to reallocate the tree array as we go down the tree.
First question: is it really a good thing to extensively use realloc() in term of efficiency?
Second question: is there a smarter way (in term of memory) of doing it?