|
How much memory does this use? |
verthex
Member #11,340
September 2009
|
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? memory2.push_back(0); return 0; }
|
Matthew Leverton
Supreme Loser
January 1999
|
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. |
verthex
Member #11,340
September 2009
|
So an empty vector does have overhead, thats what I was wondering.
|
Bernardo Lopes
Member #510
July 2000
|
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?
|
verthex
Member #11,340
September 2009
|
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
Supreme Loser
January 1999
|
Bernardo Lopes said: 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 ~~
Member #2,749
September 2002
|
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 ----------- |
|