Nested STL vector using way too much memory

后端 未结 6 1475
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 16:19

I have an STL vector My_Partition_Vector of Partition objects, defined as

struct Partition // the event log data structure
{
    in         


        
6条回答
  •  再見小時候
    2021-01-06 16:55

    16 bytes is a complete and total waste. You're storing a hell of a lot of data about very small objects. A vector of vector is the wrong solution to use. You should log sizeof(vector) - it's not insignificant, as it performs a substantial function. On my compiler, sizeof(vector) is 20. So each Partition is 4 + 4 + 16 + 20 + 20*number of inner partitions + memory overheads like the vectors not being the perfect size.

    You're only storing 16 bytes of data, and wasting ridiculous amounts of memory allocating them in the most segregated, highest overhead way you could possibly think of. The vector doesn't use a lot of memory - you have a terrible design.

提交回复
热议问题