32k Variable Size Limit 'in' Think Pascal 
Author Message
 32k Variable Size Limit 'in' Think Pascal

Hello all :-).

Does anyone know how it is possible to get around the (fundamental?)
restriction on size of variables (that restriction effectively being
approx. 32k) 'in' Think Pascal? I realise that this is a Mac-related
issue but am wondering if it can be circumvented in or using Think Pascal
itself. I desperately need a massive array :-).

The exact Think error received is "Available memory for variables
declared at this level has been exhausted." received when compiling a
program with an fixed array larger than 32kb in size.

Thank you greatly in advance!

Chris Wood



Sat, 09 Aug 2003 02:08:56 GMT  
 32k Variable Size Limit 'in' Think Pascal

Quote:

> Does anyone know how it is possible to get around the (fundamental?)
> restriction on size of variables (that restriction effectively being
> approx. 32k) 'in' Think Pascal? I realise that this is a Mac-related
> issue but am wondering if it can be circumvented in or using Think Pascal
> itself. I desperately need a massive array :-).

Does "Think Pascal" supports the pointers and dynamic memory allocation
procs (such as Borland's New(), Dispose(), GetMem(), FreeMem(), etc..)?
No way to help You, if it doesn't...

--
LLAP!  Alexey Broushkovsky AKA Gloom,



Sat, 09 Aug 2003 04:14:46 GMT  
 32k Variable Size Limit 'in' Think Pascal

Quote:
> Does anyone know how it is possible to get around the (fundamental?)
> restriction on size of variables (that restriction effectively being
> approx. 32k) 'in' Think Pascal? I realise that this is a Mac-related
> issue but am wondering if it can be circumvented in or using Think Pascal
> itself. I desperately need a massive array :-).

> The exact Think error received is "Available memory for variables
> declared at this level has been exhausted." received when compiling a
> program with an fixed array larger than 32kb in size.

First question: why 32 KB? With INTEL you're stuck to 64 KB because that's
how the (older) CPUs worked.
Second question: does Think know something like rangechecking and if, can it
be disabled? I sometimes need exactly 64 KB. Declaring an array of 64 KB is
impossible for whatever reason, you'll come one or two bytes short. So I
declare two arrays of 32 KB, make sure they are declared one after the
other:

type
  T32KB = array[0..$7FFF] of byte;

var
  Buffer, Buffer2 : ^T32KB;

All read/write operations are done with Buffer with rangechecking off like

{$R-} for w := 0 to $FFFF do Buffer^[w] := $55; {$R+}

Good luck.

Groetjes, Ruud

http://home.hccnet.nl/g.baltissen/index.htm



Sat, 09 Aug 2003 15:28:46 GMT  
 32k Variable Size Limit 'in' Think Pascal

Quote:

> > Does anyone know how it is possible to get around the (fundamental?)
> > restriction on size of variables (that restriction effectively being
> > approx. 32k) 'in' Think Pascal? I realise that this is a Mac-related
> > issue but am wondering if it can be circumvented in or using Think Pascal
> > itself. I desperately need a massive array :-).

> > The exact Think error received is "Available memory for variables
> > declared at this level has been exhausted." received when compiling a
> > program with an fixed array larger than 32kb in size.

> First question: why 32 KB? With INTEL you're stuck to 64 KB because that's
> how the (older) CPUs worked.

The origin is from the original 68000 instruction set.  Instruction
addressing modes with immediate displacements were limited to a maximum
relative offset of a signed 16 bit displacement (i.e., +- 32K).  While
it was possible to work with larger relative displacements with the
original 68K, you had to use less efficient instruction sequences and
addressing modes.  (The address space is linear so it doesn't present
the headaches involved in dealing with x86 64K segments.)

For example, the 68K link instruction is a good, single instruction for
setting up a stack frame on routine entry; however, with the original
68K the frame size/stack displacement was limited to a signed 16 bit
quantity.  You could get around the limit with a sequence of move
instructions and a 32 bit long add instruction which duplicated the
link instruction's behavior only with a 32 bit stack displacement
instead of a 16 bit displacement.   (Since 32K was a major fraction of
available memory in early model Macintoshes, it didn't make much sense
to implement the less efficient large stack frame code in compilers
since code requiring large stack frames wouldn't run anyway due to lack
of memory.)

In newer 68K versions starting with the 68020, 32 bit immediate
displacements were added to the instruction set addressing modes.  This
along with Macintoshes with larger memories led some compiler vendors
to remove 32K limitations from their compilers (e.g., MPW Pascal).  The
price for no limits while generating code compatible with the original
68K instruction set is slightly larger code size and slightly slower
performance.  

Quote:
> Second question: does Think know something like rangechecking and if, can it
> be disabled? I sometimes need exactly 64 KB. Declaring an array of 64 KB is
> impossible for whatever reason, you'll come one or two bytes short. So I
> declare two arrays of 32 KB, make sure they are declared one after the
> other:

> type
>   T32KB = array[0..$7FFF] of byte;

> var
>   Buffer, Buffer2 : ^T32KB;

> All read/write operations are done with Buffer with rangechecking off like

> {$R-} for w := 0 to $FFFF do Buffer^[w] := $55; {$R+}

THINK Pascal has range checking with provisions for programmer control.
One of the provisions is the same {$R-} {$R+} compiler directives you
are familiar with.

However, with fixed size pointer based arrays, you don't have to resort
to the above style of code.  With pointer based structures, there isn't
a 32K limit and where the size is known at compile time there is no
need to turn off range checking.  A 64K buffer example similar to the
above written for THINK Pascal would look like:

type
  T64KB = packed array[1..$0FFFF] of char;

var
  Buffer : ^T64KB;
  w : longint;

...

new(Buffer);
for w := 1 to $0FFFF do Buffer^[w] := chr($55);

Note there is no need to turn off range checking.  Note also that since
THINK Pascal doesn't have a built-in unsigned integer type, array index
related types need to be longint (i.e., 32 bit) to aviod sign problems
with 64K buffer index arithmetic.  (THINK types a five digit hex value
as a longint.)

Gale Paeper



Sat, 09 Aug 2003 22:32:15 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. THINK Pascal, for pc's?

2. Help!: 'Invalid variable reference'

3. Wolfenstein - thought that'd get your attention...

4. I think it's the right time...

5. 32K limit in TDBMemos

6. BLOB limited to 32k?

7. Are ODBC Blobs limited to 32K?

8. Get rid of 32k limit in Memo!!!!

9. Reading different size variables from same open file in Turbo Pascal 3.0

10. It's is size that matters

11. BDE coulden't update a Varchar Field: Size 50, Phisycal Length 51

12. Setting Printer's Page Size From Program

 

 
Powered by phpBB® Forum Software