Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jarthur!ucivax!megatek!hobbes!hollen From: hollen@megatek.UUCP (Dion Hollenbeck) Newsgroups: comp.os.msdos.misc Subject: Re: !@#$ 64k segments! Message-ID: Date: 8 Apr 91 15:14:01 GMT References: <14049@ccncsu.ColoState.EDU> Sender: hollen@megatek.UUCP Organization: Megatek Corporation, San Diego, California Lines: 38 In-reply-to: millerje@mozart.cs.colostate.edu's message of 7 Apr 91 20:51:15 GMT In article <14049@ccncsu.ColoState.EDU> millerje@mozart.cs.colostate.edu (Jeff Miller) writes: > I am writing a program in C, and just to make life easy, I want to malloc > (actually calloc) a data space > 64k. I noticed that if I malloc <65535 > bytes (<64k) I can fread directly into that buffer. What I'd like to do > is be able to fread into a buffer about 256k in size. (The reason for this > is speed). I have tried the large memory model as well as huge pointers, but > to no avail. Are there any special versions of malloc &/or calloc that > will let me do this? Well, you can and you can't. There are either library functions available to get a DOS memory block, or you can do an interrupt to DOS directly to allocate it. However, the problem comes with the fread. You finally get down to the disk controller level, no matter whether you do a read or fread and the disk controller uses the 80x86 instruction set. There is no instruction that can operate on >64k. To do that, you need to break it down into 64k chunks at some level and do them one at a time. I think the best that you can do is to allocate the huge chunk, and read the file in 64k chunks (or go to a 68000 or SPARC running UNIX with a 32 bit linear address space). Your problem is running smack up against the hardware architecture and there is not much you can do about it. BTW, in the old 8088's you had to watch out for floppy disk reads that crossed 64k boundaries. This was of course handled in the BIOS transparently, but if you read as little as 512 bytes from the floppy and asked it to be put at 2000:fff0, it would transfer the first 10h bytes, increment the segment pointer and transfer the rest of the 512. This is because the DMA controller would not cross 64k boundaries. Be thankful you don't write BIOS's and only have applications to worry about. -- ----- Dion Hollenbeck (619) 455-5590 x2814 Megatek Corporation, 9645 Scranton Road, San Diego, CA 92121 uunet!megatek!hollen or hollen@megatek.uucp