reading binary data in C

Spannring icsu7039 at ming.cs.montana.edu
Fri May 31 10:27:48 AEST 1991


In article <KRASIC.91May24165634 at tucana.mpr.ca> krasic at tucana.mpr.ca (Charles Krasic) writes:
[ lines about wanting to bring a chunk of a binary file into memory deleted ]
>
>	1)  mmap the chunk of the file into memory with 
>	    flags set to MAP_PRIVATE

I've never heard of mmap before and our man pages haven't either.  I
would guess it isn't portable, so I'd avoid it.

>	2)  malloc a chunk of memory and use either
>	    i) fread

Probaly not too bad, but if you are bringing in big (>=512 bytes)
chunks of data, why not go directly to the system calls and use read?
Should be about as fast as you can get.

>	    or ii) fgetc

I would guess somewhat slow.


--
====================================================================
 Six of one, 110 (base 2) of       | Craig Spannring
 another.                          | icsu7039 at caesar.cs.montana.edu
 ----------------------------------+--------------------------------



More information about the Comp.unix.programmer mailing list