In the last post, we discussed the cost of using STL vector to module size. Now let’s take a look at how STL vector manages its data. Dia2Dump (Source code available in Microsoft Visual Studio 8\Dia SDK\Samples\Dia2Dump directory) shows the following internal structure of vector<short:> UDT : std::vector<short,std::allocator<short> > BaseClass : std::_Vector_val<short,std::allocator<short> >, offset = 0x0 BaseClass : std::_Container_base, offset = 0x0 Data : this+0x0, Member, Type: class std::allocator<short>, _Alval Data : this+0x4, Member, Type: short *, _Myfirst Data : this+0x8, Member, Type: short *, _Mylast Data : this+0xc, Member, Type: short *, _Myend Class vector<short> derives from _Vector_val<short>, which in turn derives from _Container_base. _Vector_val has one member variable, _Alval, which is of the type allocator<short>. Also allocator<short> does not have any member variable; its still occupies 1-byte space. Due
Read More...