I have 2 sets created with 'new': (symbolic write)
set1 = {10, 15, 20, 21, 50}
set2 = {1, 5, 20, 21, 150}
I want to create the sum of sets so I allocate with newint[sizeof(set1) + sizeof(set2)] which is 5+5=10 positions.
but the addition is:
set3 = {1, 5, 10, 15, 20, 21, 50, 150}
and it has 8 positions.
Can I shrink, after the addition operation, the heap block, without copying everything to a new buffer? Like realloc.
I use something like this in really big SparseVector and SparseMatrix so I don't want to use std::vector because it has 3 members instead of 2 than I use. (std::vector uses an extra member for capacity())
"Can I shrink, after the addition operation, the heap block, without copying everything to a new buffer? Like realloc."
No; you'll have to do it manually.
chameleon wrote:
"I don't want to use std::vector because it has 3 members instead of 2 than I use."
Two members are for marking the end of the allocated region, while the other is for marking the next available slot. All three are required to create a safe storage container.