home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!natinst.com!news.dell.com!swrinde!emory!europa.asd.contel.com!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!uknet!edcastle!dcs.ed.ac.uk!jaxh
- From: jaxh@dcs.ed.ac.uk (Jon Hanson)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: fread() in C
- Message-ID: <Bz9F0u.FEx@dcs.ed.ac.uk>
- Date: 14 Dec 92 17:24:29 GMT
- References: <BysKr2.3vu@dcs.ed.ac.uk> <Ixw6s*Su2@spirits.ka.sub.org>
- Sender: cnews@dcs.ed.ac.uk (UseNet News Admin)
- Organization: Department of Computer Science, University of Edinburgh
- Lines: 31
-
- In article <Ixw6s*Su2@spirits.ka.sub.org>, rob@spirits.ka.sub.org (Roland Bless) writes:
- > In article <BysKr2.3vu@dcs.ed.ac.uk>, Jon Hanson writes:
- >
- > > I'm using fread() to read a large portion of a file into memory, using something like,
- > >
- > > buffer = (struct [...] *) AllocMem(bufflen,MEMF_PUBLIC|...);
- > > if (buffer) fread(&buffer,1,bufflen,fileptr);
- > > where bufflen is the portion lenght in bytes.
- >
- > You should better use fread(&buffer,bufflen,1,fileptr); which means
- > to read bufflen bytes in 1 block instead of reading bufflen*1-byte blocks.
- >
- > With ANSI-C <bufflen> is type size_t which is library dependent. This could
- > be "int" or "long int". If you link with 16-bit int's, so size_t is 16-bit,
- > you might run into problems with buffer sizes >64kB.
- >
- > > crashes. Is there some problem with using fread() with large'ish read lengths ?
- >
- > You should be aware what size the number arguments have.
- >
- > Regards,
- > Roland
-
- To all the people who said that i should have put fread(buffer,..) not &buffer, this
- was actually a typo - I was using 'buffer`. The above seems like a possible solution.
-
- Thanks for the help anyway.
-
- .
- |on Hanson
- `-' jaxh@dcs.ed.ac.uk
-