c++memorysizeofoctree

C++ Using sizeof() to determine size of an Octree


Let's say Octree() is a container with Elements of type double.

Can I use sizeof(Octree) to determine how much memory in bytes is taken up by my octree?

Sizeof() should change if I change the resolution/depth of my octree - which does not seem to be the case when I test it.

Is there a way I could determine the dynamically allocated memory size of my octree?


Solution

  • No. sizeof returns the size of the object. Which is the size of the type of the object. Which remains constant through the entire program. sizeof does not return the amount of memory that member functions of the object have allocated dynamically, and it cannot be overloaded to do so.

    Is there a way I could determine the dynamically allocated memory size of my octree?

    Certainly. You can keep track of all dynamic memory that you allocate, and their sizes together to get the total. This won't include overhead consumed by the data structure used by the allocator itself. There's no standard way to measure that.