large arrays of globals 
Author Message
 large arrays of globals

Quote:
>A month age I bought Turbo Pascal 1.5 for windows, in order to use
>a program for spectral data analysis. The experimental data are
>typically 8000 xy points.
>In the program (written originally in VAX pascal) they are globally
>declared in an array of records, each record containing x and y of
>real. Now TP stores this array in the data segment and the size of
>the array is limited to about 1500 points.

     Sorry, I'm not a Turbo user, but the following might help.  If the
problem is having a global section that is too big, simply "cheat" and declare
the variable within a procedure, where it will be allocated on the stack.  You
may need to "wrap" much of your program this way, but so what?

  PROGRAM original;             PROGRAM wrapped;
  { globals }                             { globals }
  { big arrays }                         PROCEDURE wrapper;
  { procedures }                         { big arrays }
                                                  { procedures }
  BEGIN    { main }
   procedure1;                           BEGIN   { wrapper }
   procedure2                              procedure1;
  END.                                         procedure2
                                                  END;
                                               BEGIN   { main }
                                                 wrapper
                                               END.

Quote:
>Is there some sort of malloc function as in C?

     The answer (for Borland) is, I believe, yes, but I'm not the one to help,
here.

Bob Schor
Pascal Enthusiast



Wed, 18 Jun 1902 08:00:00 GMT  
 large arrays of globals

Quote:

>Hello
>A month age I bought Turbo Pascal 1.5 for windows, in order to use
>a program for spectral data analysis. The experimental data are
>typically 8000 xy points.
>In the program (written originally in VAX pascal) they are globally
>declared in an array of records, each record containing x and y of
>real. Now TP stores this array in the data segment and the size of
>the array is limited to about 1500 points.
>Isn't there a way to get round this limitation? I don't want to
>transform the array to a linked list as that would mean rewriting
>the whole program.
>Is there some sort of malloc function as in C?
>Will it work better in Windows95?

I recommend purchasing Delphi for Windows, which has a more convenient
representation of classes (more natural syntax), and which nevertheless
basically *is* Turbo Pascal.

Next, you need to create a class with a method to read and write any requested
(x,y) data point.  This method locates the appropriate point-record ... NOT
using a literal array-structure ... and returns it to the caller.  In Delphi,
you can use a method so that it APPEARS as a normal array-reference in your
program and a bunch of source-code does not have to be rewritten.

The basic problem is an architectural one:  the x86 processor uses segments
(64K each) and selectors.  It can't directly operate on more than 64K
contiguous data at a time -- not easily, anyway.  Given also that your data
point arrays are frequently "sparse," (lots of zeroes), you really want to
avoid a space-wasteful and space-consuming structure such as a literal array.

(The alternative suggestion, "use procedural variables on the stack,"
recently posted, is by the way incorrect.  The local-variables of a procedure
are located on a stack that is also 32K/64K limited.)

/mr/



Wed, 18 Jun 1902 08:00:00 GMT  
 large arrays of globals
Hello

A month age I bought Turbo Pascal 1.5 for windows, in order to use
a program for spectral data analysis. The experimental data are
typically 8000 xy points.
In the program (written originally in VAX pascal) they are globally
declared in an array of records, each record containing x and y of
real. Now TP stores this array in the data segment and the size of
the array is limited to about 1500 points.
Isn't there a way to get round this limitation? I don't want to
transform the array to a linked list as that would mean rewriting
the whole program.
Is there some sort of malloc function as in C?
Will it work better in Windows95?



Wed, 18 Jun 1902 08:00:00 GMT  
 large arrays of globals
Hello

A month age I bought Turbo Pascal 1.5 for windows, in order to use
a program for spectral data analysis. The experimental data are
typically 8000 xy points.
In the program (written originally in VAX pascal) they are globally
declared in an array of records, each record containing x and y of
real. Now TP stores this array in the data segment and the size of
the array is limited to about 1500 points.
Isn't there a way to get round this limitation? I don't want to
transform the array to a linked list as that would mean rewriting
the whole program.
Is there some sort of malloc function as in C?
Will it work better in Windows95?



Wed, 18 Jun 1902 08:00:00 GMT  
 large arrays of globals
On Wed, 03 Jan 1996 14:27:06 +0000,

Quote:
>Hello

>A month age I bought Turbo Pascal 1.5 for windows, in order to use
>a program for spectral data analysis. The experimental data are
>typically 8000 xy points.
>In the program (written originally in VAX pascal) they are globally
>declared in an array of records, each record containing x and y of
>real. Now TP stores this array in the data segment and the size of
>the array is limited to about 1500 points.

You can do several things:

First, allocate the array on the heap.  Change:

type rec = record x,y: real;  arr = array[1..1500] of rec;
var  A: arr;

to:

type    rec = record x,y: real; end;
const   lim = 65500 div sizeof(rec);
type    arr = array[1..lim] of rec;  
        Parr = ^ arr;
var  A: parr;
begin
   New( A );
...

Then change every ocurrence of A to A^.  The compiler will spot each
occurence of A for you (unless you pass A as a untyped variable).

this will give you some breathing room.

If your array is 2-dimensional, you can make each row be a pointer
to up to 65k.  This will give you lots more room.

type    rec = record x,y: real; end;
const   lim = 65500 div sizeof(rec);
type    row = array[1..lim] of rec;
       prow = ^ row;
        arr = array[1..cols] of prow;

-----------------------------------------------------------------------

Sr. Sys. Programmer                       University of Minnesota



Wed, 18 Jun 1902 08:00:00 GMT  
 large arrays of globals
On Wed, 03 Jan 1996 14:25:22 +0000, Stephen Simpson

Quote:

>A month age I bought Turbo Pascal 1.5 for windows, in order to use
>a program for spectral data analysis. The experimental data are
>typically 8000 xy points.
>In the program (written originally in VAX pascal) they are globally
>declared in an array of records, each record containing x and y of
>real. Now TP stores this array in the data segment and the size of
>the array is limited to about 1500 points.
>Isn't there a way to get round this limitation?

Yes, you can allocate memory on the heap, and have multiple 64K
blocks, or huge blocks (with a fair bit of trouble).  Use New() or
Getmem().

 I don't want to

Quote:
>transform the array to a linked list as that would mean rewriting
>the whole program.
>Is there some sort of malloc function as in C?
>Will it work better in Windows95?

Windows95 isn't really any different from Windows 3.x when running 16
bit TPW programs.  Once Borland releases the 32 bit Delphi you'll be
able to make better use of Win95 --- it should be able to allocate
your whole array just the way you did it on the VAX.

Duncan Murdoch



Wed, 18 Jun 1902 08:00:00 GMT  
 large arrays of globals

Quote:

> On Wed, 03 Jan 1996 14:27:06 +0000,

> >Hello

> >A month age I bought Turbo Pascal 1.5 for windows, in order to use
> >a program for spectral data analysis. The experimental data are
> >typically 8000 xy points.
> >In the program (written originally in VAX pascal) they are globally
> >declared in an array of records, each record containing x and y of
> >real. Now TP stores this array in the data segment and the size of
> >the array is limited to about 1500 points.

> You can do several things:

> First, allocate the array on the heap.  Change:

> type rec = record x,y: real;  arr = array[1..1500] of rec;
> var  A: arr;

> to:

> type    rec = record x,y: real; end;
> const   lim = 65500 div sizeof(rec);
> type    arr = array[1..lim] of rec;
>         Parr = ^ arr;
> var  A: parr;
> begin
>    New( A );
> ...

> Then change every ocurrence of A to A^.  The compiler will spot each
> occurence of A for you (unless you pass A as a untyped variable).

> this will give you some breathing room.

> If your array is 2-dimensional, you can make each row be a pointer
> to up to 65k.  This will give you lots more room.

> type    rec = record x,y: real; end;
> const   lim = 65500 div sizeof(rec);
> type    row = array[1..lim] of rec;
>        prow = ^ row;
>         arr = array[1..cols] of prow;

> -----------------------------------------------------------------------

> Sr. Sys. Programmer                       University of Minnesota

Thanks for your suggestion and I will certainly try it.
Meanwhile I discovered the function "GlobalAlloc" in the WINPROCS unit
that might do such a job as well. Do you have experience with it?

cheers, Hidde



Wed, 18 Jun 1902 08:00:00 GMT  
 large arrays of globals

Quote:

>A month age I bought Turbo Pascal 1.5 for windows, in order to use
>a program for spectral data analysis. The experimental data are
>typically 8000 xy points.
>declared in an array of records, each record containing x and y of
>real. ..... the array is limited to about 1500 points.
>Isn't there a way to get round this limitation? I don't want to
>transform the array to a linked list as that would mean rewriting
>the whole program.
>Is there some sort of malloc function as in C?
>Will it work better in Windows95?

A single data structure is limited to 64k in TP (Dos). Possibly also in TPW.
(certainly in BP7)

However the following may be useful:

a. MAlloc (allocate memory on the heap):
   Several command pairs are possible
    Look for:    new/dispose;  Getmem/Freemem;
    you also need to understand referencing and dereferencing of pointers
     (the use of the "^" (carat))

b. If you want 8000 elements in a single formally defined data structure (i.e
array) you will limit yourself to 64k, thus 8000 datapoints would require that
you limit x,y types to 4 byte types. By creating two arrays (X and Y) you
could get larger types, or more data points.

c. If you want huge arrays, larger than 64k, perhaps you could build a function
   x(index) which does a selection within in a linked list of 64k arrays,
where each element in the list points to a 64k array. This would allow a
relativeley small change to your program (( square brackets become round
etc... but no real change of logic) (Again a. would be necessary))

d. Unfortunately, the size of a memory block allocated with getmem is limited
to a word type, thus 64k.

Max



Wed, 18 Jun 1902 08:00:00 GMT  
 large arrays of globals


Quote:
}c. If you want huge arrays, larger than 64k, perhaps you could build a function
}   x(index) which does a selection within in a linked list of 64k arrays,
}where each element in the list points to a 64k array. This would allow a
}relativeley small change to your program (( square brackets become round
}etc... but no real change of logic) (Again a. would be necessary))

No NEED for a linked list, if you don't want one.  An array of pointers
can hold about 16380 of them, each pointing to, say, an array of 16380
"single" vars. (? Is this c.l.p.borland still ?), allowing 256MB
(other things permitting, which I doubt).

type lots = 0..16379 {255 might be more reasonable} ;
A = array [lots] of single ;
PA = ^A ;
B = array [lots] of PA ;
PB = ^B ;
var X = PB { uses 4 bytes of stack } ; j : word ;
...
New(X) ; for j := 0 to 16379 do New(X^[j]) ;
X^[123]^[234] := 3.45 ;

E&OE, but something rather like that is certainly OK.
--



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. large array of globals

2. large arrays of globals

3. large array..

4. Large array supports.

5. Large array

6. Q: storing large arrays

7. Help! Large Array

8. I need to make a large array for my Computing A-Level project - can you help

9. I need to make a large array for my Computing A-Level project - can you help

10. very large 2d array

11. Large 3D array

12. GetBitmapBits and LARGE arrays

 

 
Powered by phpBB® Forum Software