std::vector of std::vectors contiguity

后端 未结 4 1632
暗喜
暗喜 2020-12-01 15:56

I know that std::vector internally stores it\'s data contiguously (unless it is std::vector) both in the old C++03

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 16:33

    No. The elements of a vector are stored in a dynamically allocated block of memory; otherwise, the capacity of the vector could not increase. The vector object just holds a pointer to that block.

    The requirement that the elements be stored sequentially applies only to the elements themselves, and not to any dynamically allocated members of those elements.

提交回复
热议问题