Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!dfoster From: dfoster@jarthur.Claremont.EDU (Derek R. Foster) Newsgroups: comp.os.msdos.programmer Subject: Re: HELP!! Turbo-C++ FAR POINTERS Summary: There is an easier way now. New feature in C++. Message-ID: <8371@jarthur.Claremont.EDU> Date: 12 Sep 90 03:09:18 GMT References: <0093BF75.AA852DC0@EA.USL.EDU> Organization: Harvey Mudd College, Claremont, CA 91711 Lines: 68 In article <0093BF75.AA852DC0@EA.USL.EDU> johnson@EA.USL.EDU writes: >I was trying to use a very large array (char lines[1000][150];) using >Turbo-C++ on a 80-x86 based pc. I realized I needed a particular type >of pointer to address this thing, so I used a FAR pointer. However, >I did something wrong and real quickly compromised the integrity of the >FAT file on the hard-drive. (not very fun, I couldn't even boot up) > >Needless to say I don't want to do this again. How can I declare and >address this array? The fact that you declared your array as 'far' was probably the cause of your downfall. When something is added to a far pointer, the result may not exceed 64K + the segment part of the far pointer. This is due to the segmented architecture of the CPU, and to the fact that a far pointer's data is stored in two related fields in the pointer, only one of which is involved in pointer arithmetic. The solution is to declare your array as consisting of 'huge' characters, in particular, char huge lines[1000][150]; Technically, this declares lines as an array of 'huge char', which wasn't allowable syntax until the latest version of Turbo. It allows declaration of arrays > 64K. (Remember: It's not the pointer that is being declared as huge. It's the characters themselves. The pointer is automatically huge by virtue of the fact that it is a pointer to huge characters. Old versions of Turbo didn't allow 'far/huge objects', only 'far/huge pointers') (Other note: Declaring a non-pointer as far or huge also means that it is assigned its own data segment, which can be useful sometimes too. for instance: struct xyz { array[50000]; }; struct xyz far abc, far def, far ghi; allows you to declares several structures which when combined, exceed 64K, which is more than Turbo would normally allow you to put in one source file. ). Anyway, this is by far easier than dynamically allocating your array as some other posters have suggested (although there may be other benifits to dynamic allocation.) 'huge' pointers are like far pointers except that they invoke special subroutines for pointer math which insure that the entire pointer (both the segment and offset fields) are updated in pointer arithmetic. This is slower than ordinary pointer arithmetic, so use huge pointers sparingly. The advantage is that huge pointers may access data objects greater than 64K. This feature is not documented well in the C++ manual, but it does exist somewhere. If you poke around for a while, you can probably find it. > >Any help would be GREATLY appreciated. > >Lee Johnson hlj@usl.edu I hope this helps! Derek R. Foster