[Insight-developers] bug: VectorContainer::Reserve() has incorrect
semantics.
Zachary Pincus
zpincus at stanford.edu
Mon Jan 30 20:32:30 EST 2006
Hi again,
itk::VectorContainer::Reserve() states that it's purpose is to:
/**
* Tell the container to allocate enough memory to allow at least
* as many elements as the size given to be stored. This is NOT
* guaranteed to actually allocate any memory, but is useful if the
* implementation of the container allocates contiguous storage.
*/
However, internally it calls itk::VectorContainer::CreateIndex(),
which itself calls std::vector::resize(). Resize() is different than
reserve() in that the former actually *creates empty elements*,
changing the size (e.g. number of elements in) the container. Reserve
is supposed to *allocate memory* for those elements without actually
creating them (this is explicitly true for std::vector::reserve(),
and is pretty strongly implied by the documentation above for
itk::VectorContainer::Reserve().
So there's a semantic/documentaiton problem with
itk::VectorContainer::Reserve() in that it's actually a Resize()
method (which CreateIndex *also* is), and there is no true
"std::vector::reserve"-style method.
So what to do about this? Fixing it changes the API; not fixing it
leaves a dangerous mismatch between what Reserve() means to a
VectorContainer and what reserve() means to a vector.
Zach
More information about the Insight-developers
mailing list