what happens when std::vector is left empty?

Started by
3 comments, last by 215648 9 years, 11 months ago

I've 3 textures in my model class, which are:

std::vector<ID3D11ShaderResourceView*> DiffuseMapSRV;
std::vector<ID3D11ShaderResourceView*> NormalMapSRV;
std::vector<ID3D11ShaderResourceView*> AOMapSRV;
when I want to only load a specific map, I only fill that std::vector with TextureSRV and leave rest empty. (e.g-> only DiffuseMapSRV is used and rest are ignored.)
What will happen when I leave this empty? will it occupy space? what should I do?
Advertisement

Typically you want to declare your variables upon the first usage and not beforehand. Also, you don't want to declare an unused variable: this will likely produce a compiler warning and the variable is most likely removed by the compiler optimizations altogether anyways. An empty std::vector will take some bytes of memory, but the exact size depends on the used compiler, STL implementation, and target architecture. F.ex. figures for couple different MSVC implementations can be found here: http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx

Although Stinkfist's caveats are true, you can expect an empty vector to occupy something like 12 bytes in a 32-bit system and something like 24 bytes in a 64-bit system. Unless you are going to have gazillions of vectors, this should not be something to worry about.

To be more clear about the 12 and 24 bytes, it's because vector (and all array class in general) stores length,capacity and pointer of data.

At the end you have 2 size_t and one data pointer of the type of the vector, in x86 each is 4 bytes, in x64 each is 8 bytes.

Thanks for this, I understood now.

This topic is closed to new replies.

Advertisement