[vtk-developers] vtkDataReader/vtkDataWriter and vtkLongArray

Marcus D. Hanwell marcus.hanwell at kitware.com
Mon Dec 24 11:50:34 EST 2012


On Mon, Dec 24, 2012 at 9:26 AM, Utkarsh Ayachit
<utkarsh.ayachit at kitware.com> wrote:
> Folks,
>
> Try opening the attached file and save it out in legacy VTK formats
> (you can use ParaView to make it easier) saving as ASCII and  Binary.
> On a 64-bit linux machine, when load both the saved out files, the
> values for "material (long)" are different. The values read from the
> binary file are wrong.
>
> The problem is this: since long is 64-bit i.e. 8 bytes on my machine,
> when saving out binary files, the writer saves out 8 bytes in
> big-endian format handled by templated code (vtkDataWriter.cxx:996).
> However, when reading, vtkDataReader thinks long is going to be 4
> bytes and hence only consider 4 bytes when converting big-endian to
> little-endian (vtkDataReader.cxx:1578).
>
> Now since "long" doesn't have a fixed size across platforms (4 bytes
> in some cases and 8 in others), what is the best way of dealing with
> this for portable IO?
>
Isn't using fixed size types the only reasonable way to handle this
kind of thing? Using an int32 or int64 would seem like the right way
when reading/writing the data, even if our classes uses types that
vary in size across platforms.

Marcus



More information about the vtk-developers mailing list