[vtkusers] #Defines for Big or Little Endian

David Gobbi dgobbi at atamai.com
Fri Sep 1 11:19:19 EDT 2006


Mike Jackson wrote:
> On 9/1/06 10:56 AM, "Sean McBride" <sean at rogue-research.com> wrote:
>
>   
>> I believe vtkByteSwap is the only class that does anything like this.
>> You might want to search all the vtk code for "VTK_WORDS_BIGENDIAN" to
>> learn a little more about how vtk does swapping.
>>
>> Personally, I find Apple's APIs are much better named, but I believe
>> vtkByteSwap::Swap4BE(), for example, swaps a 4 byte value from host to big.
>>     
>
> No, actually vtkByteSwap::Swap4BE() does the swap period. It does not pay
> attention to if it actually _needs_ to be done. It just does it.
>   

I don't understand what you're saying here.  Swap4BE will always do a 
swap on a little-endian machine, and will never do a swap on a 
big-endian machine.  So it only does the swap if the swap needs to be done.

Likewise, Swap4LE will only do the swap on a big-endian machine.

Are you sure that you are using these methods correctly?

 - David


> In Apples code for swapping Little To System for instance there is a
> compiler check to see if the code is compiled for a Little Endian machine.
> If it _is_ compiled for a Little Endian machine then the method simply
> returns the argument that was passed in. If on the other hand the code was
> compiled on a BIG endian machine then the actual swap will take place. This
> is a nice optimization that takes place on your behalf with out any work on
> your part. 
>
>  I am reading binary files that can be Big or Little Endian or either a Big
> Or Little Endian machine. That is 4 combinations. If I use VTK's byte
> swapping code I would have to write 4 versions of my code. One covering each
> of the possibilities. By using API's such as those from Apple the compiler
> can optimize 2 of those situations away for me so I only need to write 2
> versions of my code.
>
> Unless in my newbie C++ knowledge I have completely missed something...
>
> Cheers
>   




More information about the vtkusers mailing list