How would I determine the total amount of memory an object is using, and what percentage of that memory currently exists on the stack? What about the heap as well?
For example, given this program:
#include <cstdlib> #include <vector> #include <string> int main(){ //I wonder how much memory is being //used on the stack/heap right now. std::vector<std::string> vec{"11","22","33"}; //how about now? return EXIT_SUCCESS; } how can I view the size of the stack and heap before and after the creation of the vector?
Is this possible to do this with GDB?
The manual provides some information on examining memory, but I haven't been able to report such information.
sizeof vecwill be the stack size it takes since you allocated it on the stack. The free store size should be something likevec.capacity() * sizeof(std::string).