Answer the question
In order to leave comments, you need to log in
Sizeof(std::vector) =?
In std the value of this function ( for x32 ) sizeof(vector<int>)
= 20
Question - why?
My guesses:
4 bytes - a pointer to the beginning of the array
4 bytes - a pointer to the position where the next element will be written (well, that is, fullness)
4 bytes - a pointer to the end of the allocated memory
Total 12 bytes. Where are the 8 more? I suspect there is still a pointer to the allocator, but it's still 4 bytes
. Where am I wrong and what is missing?
Answer the question
In order to leave comments, you need to log in
+_Vector_val::_Container_base::_Container_proxy _Myproxy;
+_Vector_val::_Alty _Alval;
Well, firstly, the vector allocates memory with a margin. So most likely he still needs to store the number of reserved elements (total) and the number of added elements. In general, open the debugger and take a look.
It depends on the stl implementation. In the stl bundled with gcc-4.6 on a 32-bit platform, sizeof(vector) is 12, three 4-byte pointers:
typename _Tp_alloc_type::pointer _M_start;
typename _Tp_alloc_type::pointer _M_finish;
typename _Tp_alloc_type::pointer _M_end_of_storage;
allocator_type _M_data_allocator;
_Tp* _M_start;
_Tp* _M_finish;
_Tp* _M_end_of_storage;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question