How much memory does this use?

This is a really simple question which is actually obvious although I'm not sure if it its wrong on my behalf so here is the code. I left comments related to the question.

#include <vector>

int main()
  int memory1 = 0;//does memory1 use more memory than memory2
  std::vector<int> memory2;//does this use any memory at all?

  //now are they the same? or is memory 2 larger in size?

  return 0;

Matthew Leverton

Use sizeof to see. Of course it won't tell you the full memory of the vector, but it should be enough to convince you that even an empty vector has overhead.


So an empty vector does have overhead, thats what I was wondering.

Bernardo Lopes

By the way, is there a programmatically easy and direct way to find out the total amount of memory that an Allegro program is using?

Or we can only resort to sizeof every instantiation?


You could also try using Process Explorer on your machine as long as its windows I think. I have XP. It gives a lot of info about the program running in memory.

Matthew Leverton

Or we can only resort to sizeof every instantiation?

That tells you the size of the data type, which is fixed at compile time.

If you want to know how much memory Allegro is using from al_malloc() calls, set a custom memory interface and track the bytes.

Karadoc ~~

Well, at the very least I'd assume the vector has to store int* and size_t. So it would take more memory than the plain int regardless of whether or not it is empty. Also, the vector typically allocates more memory than is strictly required. You can see how much memory it has allocated for data by using std::vector::capacity

Thread #609471. Printed from