Enable reallocation of ArrayHandleBasic with moved std::vector
It is possible to create an ArrayHandleBasic
from a std::vector
. It
is possible to move the vector
into the ArrayHandle
such that the
ArrayHandle
takes over the memory. When you do this, the ArrayHandle
should be able to resize the data if necessary. However, this was not
working.
There were actually 3 problems that were colluding to lead to this incorrect behavior.
-
The
Buffer
object was not allowing the reallocation of pinned data. Pinned data means that theBuffer
's memory is pointing to some user data that should stay where it is. Instead, theBuffer
should attempt to reallocate the pinned data using its registered realloc method. This registered realloc method should be the think to throw the exception if reallocation is not supported. (Technically, the memory doesn't really need to be pinned since the data is moved and the user no longer has direct access to it. But for implementation reasons, movedvector
data is pinned.) -
The
InvalidRealloc
function was not properly throwing an exception. This was not noticed sinceBuffer
was inappropriately throwing an exception for it. -
The reallocation method
StdVectorReallocater
had a bad assert that crashed the program during reallocation.