[vtkusers] Copying memory instead of resizing allocation in vtkDataArrayTemplate::Resize()

Jens jens-devel at gmx.de
Tue Oct 25 06:41:07 EDT 2005


Hi
I would like to read grids with millions of cells and developed a reader for 
my private netCDF file format.

I thought reading the file in chunks of 100000 cells. That for I create a 
vtkDoubleArray to add all nodes of the 100000 cells and resize that 
vtkDoubleArray each time I read the next chunk of cells.

I had a look at the function resizing the vtkDoubleArray because I have to 
make sure not to use more memory than needed. ( Its "Resize()" in 
vtkCommon/vtkDataArrayTemplate.txx line 273 in Vtk-5-branch )

This function uses "memcpy" instead of "realloc" to resize the double array.
( http://www.codecogs.com/reference/stdlib.h/malloc.php?alias=realloc
http://www.codecogs.com/reference/string.h/memcpy.php?alias=memcpy )

That means that each time Resize get used the data is twice in memory for a 
short time. That´s slow and needs double memory.

What´s wrong with realloc ?

		Greetings
			Jens



More information about the vtkusers mailing list