vtkDataArrayTemplate::Resize() uses memcpy instead of realloc
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
- Resize() in vtkCommon/vtkDataArrayTemplate.txx (line 308 in Vtk-5-branch )
- ResizeAndExtend() in vtkCommon/vtkDataArrayTemplate.txx (line 252 in Vtk-5-branch )
This functions use "memcpy" instead of "realloc" to resize an array. 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.
Expecially if it get used to create grids of great size it is very important not to copy an array but to really resize it.
Example: 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.
( Just a quick link to some infos: http://www.codecogs.com/reference/stdlib.h/malloc.php?alias=realloc http://www.codecogs.com/reference/string.h/memcpy.php?alias=memcpy )