On Mon, 25 Oct 1999, Paul Barton-Davis wrote:

> In message <[EMAIL PROTECTED]>you write:
> >Paul Barton-Davis wrote:
> >> just FYI: my C++ libsoundfile uses mmap(), but still requires
> >> applications to "read" the data. it is significantly faster than using
> >> read(2) internally, however, so there might be an argument for using
> >> mmap regardless of the endianness, and then using arch-dependent
> >> macros to fetch the data from the mmapped area. for example, on a
> >> little endian machine reading from a little endian RIFF/WAV file, the
> >> macros are essentially no-ops.
> >
> >No-ops? Do you mean you don't generate ANY code for this? If so: HOW?
> 
> sorry, not very accurate. for example:
> 
>        int16 foo;
>        unsigned char *p;
> 
>        foo = get_little_endian_int16 (p)
> 
> on an LE machine, this is just:
> 
>        foo = *((int16 *) p);
> 
> on a BE machine, its a bit more complex.

Not very much:

        #include <byteswap.h>

        foo = bswap_16(*((int16 *)p));

The defined macros from GLIBC already does byte swapping in the best way
for given architecture.

                                                        Jaroslav

-----
Jaroslav Kysela <[EMAIL PROTECTED]>
SuSE Linux    http://www.suse.com
ALSA project  http://www.alsa-project.org

Reply via email to