[vtk-developers] vtkBuffer::Reallocate special case for OS X realloc()

David Gobbi david.gobbi at gmail.com
Thu Apr 21 17:33:07 EDT 2016


On Thu, Apr 21, 2016 at 2:48 PM, Sean McBride <sean at rogue-research.com>
wrote:

> Hi all,
>
> vtkBuffer::Reallocate() has this comment:
>
> // OS X's realloc does not free memory if the new block is smaller.  This
> // is a very serious problem and causes huge amount of memory to be
> // wasted. Do not use realloc on the Mac.
>
> We've been profiling our app and this OS X-only workaround is a major
> performance killer for a use case involving blending 3D datasets.  We
> measured a 250% runtime performance improvement of Render() in release
> builds by getting rid of this special-casing!  Tonnes of time was being
> spent in malloc and std::copy.
>
> It seems entirely reasonable for realloc() to not automatically recoup the
> memory if the buffer is made smaller: for all it knows, you'll soon after
> realloc it bigger again.  Also, for all we know the OS could recoup the
> memory later.
>
> This patch removes it, all tests still pass:
> <https://gitlab.kitware.com/vtk/vtk/merge_requests/1448>
>
> Any objections?
>

I agree.  My guess is that this code was added to ensure that Squeeze()
reclaims memory.  If so, then vtkGenericDataArray::Squeeze() is the method
that should have been tweaked, rather than vtkBuffer::Reallocate().

 - David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20160421/edccd77c/attachment-0001.html>


More information about the vtk-developers mailing list