Memory consumption of a pointer to vector of pointers

前端 未结 5 2151
有刺的猬
有刺的猬 2021-01-26 09:28

I am aware that the size of a pointer is fixed (not the size of the data it points to). Now given that, supposing I have a vector of data in global scope and I declare a pointer

5条回答
  •  野性不改
    2021-01-26 09:58

    my_data will occupy sizeof(std::vector*) bytes, and no more than sizeof(void*).

    *my_data will occupy sizeof(std::vector), which can be as little as 3 * sizeof(data**), i.e. no more than 3 * sizeof(void*).

    *my_data will manage sizeof(data*) * my_data->capacity() bytes of dynamic memory.


    I have grave doubts that that information will be useful in practice.

提交回复
热议问题