Allocate method of
ArrayHandle was not declared as
const. Likewise, the methods that depended on
PrepareForOutput were also not declared
The main consequence of this was that if an
ArrayHandle were passed as a
constant reference argument to a method (e.g.
const ArrayHandle<T>& arg),
then the array could not be reallocated.
This seems right at first blush. However, we have changed these methods to
const so that you can in fact reallocate the
ArrayHandle. This is
ArrayHandle is in principle a pointer to an array pointer.
Such a structure in C will allow you to change the pointer to the array,
and so in this context it makes sense for
ArrayHandle to support that as
Although this distinction will certainly be confusing to users, we think this change is correct for a variety of reasons.
- This change makes the behavior of
ArrayHandleconsistent with the behavior of
UnknownArrayHandle. The latter needed this behavior to allow
ArrayHandles to be passed as output arguments to methods that get automatically converted to
- Before this change, a
const ArrayHandle&was still multible is many way. In particular, it was possible to change the data in the array even if the array could not be resized. You could still call things like
PrepareForInOut. The fact that you could change it for some things and not others was confusing. The fact that you could call
PrepareForOutputwas doubly confusing.
- Passing a value by constant reference should be the same, from the
calling code's perspective, as passing by value. Although the function
can change an argument passed by value, that change is not propogated
back to the calling code. However, in the case of
ArrayHandle, calling by value would allow the array to be reallocated from the calling side whereas a constant reference would prevent that. This change makes the two behaviors consistent.
- The supposed assurance that the
ArrayHandlewould not be reallocated was easy to break even accidentally. If the
ArrayHandlewas assigned to another
ArrayHandle(for example as a class' member or wrapped inside of an
UnknownArrayHandle), then the array was free to be reallocated.