Skip to content

Enable reallocation of ArrayHandleBasic with moved std::vector

Kenneth Moreland requested to merge kmorel/vtk-m:realloc-moved-vector into master

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.

  1. The Buffer object was not allowing the reallocation of pinned data. Pinned data means that the Buffer's memory is pointing to some user data that should stay where it is. Instead, the Buffer 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, moved vector data is pinned.)

  2. The InvalidRealloc function was not properly throwing an exception. This was not noticed since Buffer was inappropriately throwing an exception for it.

  3. The reallocation method StdVectorReallocater had a bad assert that crashed the program during reallocation.

Merge request reports

Loading