I want to store values of a sparse-matrix to a vector.
(It is preferred to use a vector to fill the matrix and then use OpenMP/OpenCL to sort the elements, instead of use a map. For duplicate values for the same position use a callback or sum by default)
I don't want reallocation of vector because all of stored elements will be re-copied to new bigger memory storage (waste of time).
I want to allocate a starter size and when I must expand that size, a new memory block will be allocated for only new values. Old values will be remain in old memory block. So the vector will be a join between two memory blocks.
Is this possible with an allocator?
What members of std:allocator I must override?
I must change the standard?: pointer address ( reference x ) const { return &x; }
What you're describing is not a vector, it's a deque.
Vector is always a single array, all elements are stored contiguously. If a vector grows out of its allocated memory block, it must move every single element to the new block. The only way a custom allocator could satisfy your requirements if it had allocated a giant contiguous memory block from the beginning, so that each allocation request returns the same starting address -- but if you have such a block available, why not reserve the whole thing for your vector to start with?
Deque is a sequence of individual arrays, each in its own memory block. If a deque grows, a new memory block may have to be allocated so that it starts filling in the next array, but the old values (from the old arrays) are not moved anywhere (in the standard, this requirement is phrased as "An insertion at either end of the deque [...] has no effect on the validity of references to elements of the deque.")