Expose allocation in ArrayHandle.

Add an Allocate method in ArrayHandle that basically forwards the
alllocate request to the storage object. This allows some measure of
control of the array from the control side. You can allocate the array
and set values (by getting the control array portal) if you so desire.
This commit is contained in:
Kenneth Moreland 2015-02-10 15:58:41 -07:00
parent 2f781dfe7a
commit 6141e83be4
3 changed files with 26 additions and 1 deletions

@ -227,6 +227,23 @@ public:
}
}
/// \brief Allocates an array large enough to hold the given number of values.
///
/// The allocation may be done on an already existing array, but can wipe out
/// any data already in the array. This method can throw
/// ErrorControlOutOfMemory if the array cannot be allocated or
/// ErrorControlBadValue if the allocation is not feasible (for example, the
/// array storage is read-only).
///
VTKM_CONT_EXPORT
void Allocate(vtkm::Id numberOfValues)
{
this->ReleaseResourcesExecutionInternal();
this->Internals->UserPortalValid = false;
this->Internals->ControlArray.Allocate(numberOfValues);
this->Internals->ControlArrayValid = true;
}
/// \brief Reduces the size of the array without changing its values.
///
/// This method allows you to resize the array without reallocating it. The

@ -129,7 +129,9 @@ public:
///
/// The allocation may be done on an already existing array, but can wipe out
/// any data already in the array. This method can throw
/// ErrorControlOutOfMemory if the array cannot be allocated.
/// ErrorControlOutOfMemory if the array cannot be allocated or
/// ErrorControlBadValue if the allocation is not feasible (for example, the
/// array storage is read-only).
///
VTKM_CONT_EXPORT
void Allocate(vtkm::Id numberOfValues);

@ -113,6 +113,12 @@ struct TryArrayHandleType
"Array size did not shrink correctly.");
CheckArray(arrayHandle);
std::cout << "Try reallocating array." << std::endl;
arrayHandle.Allocate(ARRAY_SIZE*2);
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE*2,
"Array size did not allocate correctly.");
// No point in checking values. This method can invalidate them.
std::cout << "Try in place operation." << std::endl;
{
typedef typename vtkm::cont::ArrayHandle<T>::template