In case you want the index access in a constant time, this is not possible, as the array might be between other heap variables.
The closest thing you can get is realloc
. This gives you the possibility to increase an existing memory allocation. But if this is not possible, it will copy the contents to a new location.
Depending on your problem, there might be other solutions to this problems:
std::vector
+ reserve()
std::list
realloc
Some mixing is also possible. You may store a list of pointers to blocks of e.g. 10000 Elements and overload the index operator.