Article View: comp.os.msdos.programmer
Article #2224Re: Huge arrays in Turbo C++
From: Sean Malloy
Date: Fri, 14 Sep 1990 14:14
Date: Fri, 14 Sep 1990 14:14
47 lines
2830 bytes
2830 bytes
In article <VXC%X%#@rpi.edu> sigma@pawl.rpi.edu (Kevin J Martin) writes:
>ajai@sce.carleton.ca (Ajai Sehgal) writes:
>> float huge image[1024][1024]
>> float huge psf[1024][1024]
>I don't know what you're getting out of this (ie, why the addresses come out
>the same), but I'm surprised it compiles. You certainly won't get a
>1024x1024 array of floats out of it - 1024x1024 char array would take a
>megabyte, and even farmalloc() only uses conventional memory!
The reason that the variables point to the same address is simple --
regardless of the data type, a 1024x1024 array will wrap an integral
number of times around the complete address space on a PC-class
machine. For example, with a 32-bit data type, each array will wrap
the address space four times. Since the address space is wrapped
completely, the compiler will give the 'next' available address, which
is the same address as the previous array, to the second array
declaration.
More graphically:
0K 1024K
|----|----|----|----|----|----|----|----|----|----|
image: |---->---->---->---->
>---->---->---->---->---->---->---->---->---->---->
>---->---->---->---->---->---->---->---->---->---->
>---->---->---->---->---->---->---->---->---->---->
>---->---->---->---->---->----|
psf: |---->---->---->---->
>---->---->---->---->---->---->---->---->---->---->
>---->---->---->---->---->---->---->---->---->---->
>---->---->---->---->---->---->---->---->---->---->
>---->---->---->---->---->----|
Realistically, the compiler should check for something like this, but
I'd be willing to bet that the Borland people didn't even consider the
idea that someone would be so unaware of hardware limitations to try
to declare two 4Mb arrays in a program for a machine with a 1Mb
address space.
| "The three most dangerous
Sean Malloy | things in the world are a
Navy Personnel Research & Development Center | programmer with a soldering
San Diego, CA 92152-6800 | iron, a hardware type with a
malloy@nprdc.navy.mil | program patch, and a user
| with an idea."
Technical Details
Message-ID:
<9561@skinner.nprdc.arpa>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!usc!ucsd!nprdc!malloyReferences:
<ajai.653150092@talos.sce.carleton.ca> <VXC%X%#@rpi.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!usc!ucsd!nprdc!malloy From: malloy@nprdc.arpa (Sean Malloy) Newsgroups: comp.os.msdos.programmer Subject: Re: Huge arrays in Turbo C++ Keywords: turbo c++ Message-ID: <9561@skinner.nprdc.arpa> Date: 14 Sep 90 14:14:44 GMT References: <ajai.653150092@talos.sce.carleton.ca> <VXC%X%#@rpi.edu> Reply-To: malloy@nprdc.arpa (Sean Malloy) Organization: Navy Personnel R&D Center, San Diego Lines: 47