Is this normal behavior for a std::vector?

前端 未结 3 1232
不思量自难忘°
不思量自难忘° 2021-01-16 03:40

I have a std::vector of a class called OGLSHAPE.

each shape has a vector of SHAPECONTOUR struct which has a vector of float and a vector of vector of double. it also

3条回答
  •  逝去的感伤
    2021-01-16 04:08

    Use the correct tools to observe your memory usage, e.g. (on Windows) use Process Explorer and observe Private Bytes. Don't look at Virtual Address Space since that shows the highest memory address in use. Fragmentation is the cause of a big difference between both values.

    Also realize that there are a lot of layers in between your application and the operating system:

    • the std::vector does not necessarily free all memory immediately (see tip of hkaiser)
    • the C Run Time does not always return all memory to the operating system
    • the Operating System's Heap routines may not be able to free all memory because it can only free full pages (of 4 KB). If 1 byte of a 4KB page is stil used, the page cannot be freed.

提交回复
热议问题