开发者

std::vector member functions

开发者 https://www.devze.com 2023-02-20 12:48 出处:网络
I saw this questio开发者_开发百科n in a book: What member functions of the std::vector are controlling the allocated memory ?

I saw this questio开发者_开发百科n in a book:

What member functions of the std::vector are controlling the allocated memory ?

Can someone answer this?

Thank you


Memory allocations of Container classes is managed by the underlying Allocator defined for each of them.
Almost All member functions will control the allocated memory.


The expected answer to this is probably resize, reserve and clear although the latter does not in fact control the allocated memory, it just resets the “known” size to zero without modifying the underlying buffer.


All of them. None of them. It's an implementation detail. You do not know and it does not matter.


The default constructor may or may not allocate memory.

Other constructors will allocate memory if the vector is not initially empty, and may or may not if it is empty.

operator=, assign, insert, push_back, reserve and resize will reallocate memory if the new size or capacity exceeds the current capacity, and will not otherwise.

The destructor will free any allocated memory.

No other member function will change the memory allocation, although some may change or invalidate the memory contents.


http://msdn.microsoft.com/en-us/library/k449z507(v=VS.100).aspx

There are limits to asking questions on this place that are answered by googling "vector member functions".

0

精彩评论

暂无评论...
验证码 换一张
取 消