Let's say I'm writing a custom vector using the
T* allocate( std::size_t n );
void deallocate( T* p, std::size_t n );
Let's say I'm writing a custom vector using the std::allocator to wrap new and delete.
In the general case (excluding specializations for PODs), I don't think you could use
realloc in any case. An arbitrary object, constructed at a specific memory location, might have internal pointers pointing to very specific addresses in relation to the address in which it was constructed. Simply moving it around (in the byte-copying sense) could break invariants.
Thus the alternative you mention is in general necessary. You would have to allocate a new array,
move (or possibly even
copy!) the objects to the new location, then deallocate the old array. Of course, this includes more than a single stage that can fail - another reason why you can't really
reallocate in the general case. Perhaps this is the reason that allocators never had this functionality in the first case - for array-based containers, you can't really use them in general (although you might be able to use them for POD specializations).