i cant see why this struct takes up 96 bytes of ram.
struct cell
{
bool filled;
bool isParent;
short int mat;
bool cx,cy,cz;
vect norm;
struct cell* child[8];
struct cell* parent;
cell(float pxx=0, float pyy=0, float pzz=0, float ss=0, cell *par=NULL, bool cxx=0, bool cyy=0, bool czz=0);
void open_read(string);
};
I know about word allignment, but this should atleast not be more than 64 bytes i think…
there will be many millions of instances of this struct so how could i get the memory footprint to a minimum?
I am using linux and vect is a vector(3 floats)
There’s not much you can do about your pointers.
However, you can condense all your booleans down to a single byte by using either single-bit enumerators or bitfields. Depending on the maximum value of
mat, you may be able to condense the flags AND that value into two bytes. It’s not a big saving.If you expect your tree to be extremely dense, you may get significant gains by allocating your children as a pool. That is, you have a single
struct cell* childpointer which references a block of memory that is an array of all eight children. Then you save the space of 7 pointers per record with the understanding that every non-leaf node will allocate more memory than it requires. And you probably need a flag to indicate the node is empty.Alternatively, you could chain your children as a list if you want to sacrifice the random-access of an array. Then you just need a single
childpointer and a singlesiblingpointer. A saving of 6 pointers per node and no wastage from pooling. It gets a bit finnicky though.