Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!munnari.oz.au!mel.dit.csiro.au!yarra!bohra.cpg.oz.au!ejp From: ejp@bohra.cpg.oz.au (Esmond Pitt) Newsgroups: comp.os.os2.programmer Subject: Re: Reading more than 64K Message-ID: <1991May1.043104.29860@bohra.cpg.oz.au> Date: 1 May 91 04:31:04 GMT References: <1991Apr30.200832.9352@ccad.uiowa.edu> Distribution: comp.os.os2.programmer Organization: Software Division, Computer Power Group Lines: 31 In article <1991Apr30.200832.9352@ccad.uiowa.edu> cadsi@ccad.uiowa.edu (CADSI) writes: > From article , by so-ecs@stekt1.oulu.fi (Juha Ruotsalainen ti): >> How can my program read a file bigger than 64k into memory. At the >> moment I try to read 64k`s at a time and the rest of it (less than >> 64k) afterwards. But after I`ve read 0xffff bytes, the next DosRead >> reads only 1 byte. > > Is this a problem with the fact that read and write can only r/w > 64K - 1 bytes at a time, noting the fact that the error status > return (-1) from read and write represents 64K exactly??? You're talking about read(). Juha asked about DosRead(). Let's talk about DosRead(). It doesn't return -1 on error at all, and even if it did, -1 does not represent '64k exactly'. 64k is (65536 == 0x10000), not (65535 == 0xffff == 64k - 1). The answer to Juha's question is that DosRead() can only read 0xffff bytes at a time. This is 1 short of 64k. After the DosRead() of 0xffff, the 64k segment then has 1 byte left in it. The second DosRead() therefore reads 1 byte into it. DosRead() won't cross segment boundaries. Juha then has to increment the selector returned by his DosAllocHuge() to form an address for the beginning of the linearly next segment, into which he should do more DosRead() calls, and so on. How are you, Juha? -- Esmond Pitt, Computer Power Group ejp@bohra.cpg.oz