Sorry if the question is not clear; It was very difficult for me to explain in one sentence.
Say I have a struct with an element that is a struct , for example. following:
struct A { struct B b; };
Suppose I assume that instances of this structure will always be distributed in heaps. Is there something you can get by changing this to this? (i.e. holding the pointer to struct B )
struct A { struct B *b; };
In the latter case, I would have several functions, such as make_A and free_A , that were free_A allocating and de-allocating the memory pointed to by b ;
The only example I can imagine where the second form may be preferable is when not all instances of struct A actually use b . In this case, the memory can be saved by allocating additional memory for those instances that require it.
Are there other cases where the second form offers something useful?
zalza
source share