[Insight-developers] bug: VectorContainer::Reserve() has incorrect semantics.

Zachary Pincus zpincus at stanford.edu
Mon Feb 13 14:20:29 EST 2006


Just a ping -- does anyone have any idea as to what to do about the  
below issue?

At the very least, the documentation should be changed, and a  
workaround of using 'vector->std::vector::reserve()' instead of  
'vector->Reserve()' should be provided. This doesn't change any APIs,  
but it's not a good solution.

Zach

On Jan 30, 2006, at 7:32 PM, Zachary Pincus wrote:

> 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
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers



More information about the Insight-developers mailing list