Board index » delphi » Data segment too large

Data segment too large

Quote
>    I'm coding a database to use in a program and it has lots of arrays of
> arrays of arrays... and I was getting error message "Too many variables."
> when tried to compile it. So I put some variables in an unit, too bypass
> that check, but now it says "Data segment too large."
>    Does anyone have an idea of how to solve this problem?

   This is a FAQ, and complete explanations would be best sought from one
of the FAQs which are mentioned here weekly.  However, the most common
solution to this problem is to use pointers to allocate and access some
(much?) of your data variables.  Since you've admitted a lot of "array"
usage, I'm pretty sure you'll be needing to learn about and use Pascal
pointers.
 

Re:Data segment too large


   I'm coding a database to use in a program and it has lots of arrays of
arrays of arrays... and I was getting error message "Too many variables."
when tried to compile it. So I put some variables in an unit, too bypass
that check, but now it says "Data segment too large."
   Does anyone have an idea of how to solve this problem?

Re:Data segment too large


Quote
vengeance <vengea...@softhome.net> wrote:
>    I'm coding a database to use in a program and it has lots of arrays of
> arrays of arrays... and I was getting error message "Too many variables."
> when tried to compile it. So I put some variables in an unit, too bypass
> that check, but now it says "Data segment too large."
>    Does anyone have an idea of how to solve this problem?

In a word: pointers.

For a more complete answer, fill in the ellipses (...) below with whatever
values you are using. Of course the program statement assumes certain
restrictions on those, but that is trivial to change if they are not met.

type
  array1  = array[...] of ...;
  parray1 = ^array1;
  array2  = array[...] of parray1;
  parray2 = ^array2;
  array3  = array[...] of parray2;

var
  demo: array3;

begin
  demo[1]^[2]^[3] = 0;
end;

Of course there is little point in having arrays of arrays of arrays. It is
much simpler to have a multidimensional array and allocate it on the heap,
e.g.

type
  bigarray  = array[..., ..., ...] of ...;
  pbigarray = ^bigarray;
var
  myarray: pbigarray;

begin
  myarray^[1, 2, 3] = 0;
end;

effectively does the same thing as above, but with less mucking around.

--
______________________________________________________________________
     The Scarlet Manuka,      |        Nitpickers' Party motto:
  Pratchett Quoter At Large,  |  "He who guards his lips guards his
 First Prophet of Bonni, is:  |  soul, but he who speaks rashly will
   sa...@maths.uwa.edu.au     |    come to ruin." -- Proverbs 13:3
______________________________|_______________________________________

Re:Data segment too large


In article <8a4s9e$uf...@enyo.uwa.edu.au>,
The Scarlet Manuka <sa...@maths.uwa.edu.au> wrote:

Quote

>Of course there is little point in having arrays of arrays of arrays. It is
>much simpler to have a multidimensional array and allocate it on the heap,

Actually there is a reason. It is just the 64K limit. A single pointer
array can hold only 16000 elements. By making an array of pointer
arrays, one can easily hold as much elements as there is memory. This is
especially relevant to BP.

Quote
>e.g.

>type
>  bigarray  = array[..., ..., ...] of ...;
>  pbigarray = ^bigarray;
>var
>  myarray: pbigarray;

>begin
>  myarray^[1, 2, 3] = 0;
>end;

There still is 64K limit on the bigarray. But if you break it from
different point:

type Subarray=array[...,...] of ...

    BigArray=array[...] or Subarray;

Var myarray:BigArray;
    i:integer;

Begin
  for i:=... to ... do new(Myarray[i]);  
  myarray[1]^[2,3]:=0;
End;

Then one can break the 64K barrier. Note also that one has to allocate.
You did not allocate (or use ... in place of it)

Now lets say it was 100x100x100xinteger. In this case it would take two
million bytes (perfectly OK on BP). It would, however, take only 400
bytes from the data segment. Each 100x100 element would take about 20K
so there is no limit there either.

If the array is one-dimensional, then breaking it is harder. Basically
you break it into two dimensions by using div/mod on indexing (or
shr/and which are faster), like a[i shr 10]^[i and 1023]:=.... It might
be nicer to write an object wit routines to set and get elements.

Osmo

Re:Data segment too large


vengeance <vengea...@softhome.net> wrote in article
<8a48bo$n7...@news.mandic.com.br>...

Quote
>    I'm coding a database to use in a program and it has lots of arrays of
> arrays of arrays... and I was getting error message "Too many variables."
> when tried to compile it. So I put some variables in an unit, too bypass
> that check, but now it says "Data segment too large."
>    Does anyone have an idea of how to solve this problem?

Overall size of your GLOBAL variables can't exceed 64k.
You can use dinamic variables that stored in heap, use NEW or GETMEM to
allocate them, and refer with pointers, like this:

********** BEFORE
type
  MyType=array [1..20] of array [1..30] of integer;
var
  MyVar:Mytype;
begin
...
MyVar[i][j]:=1;
...
***********AFTER
type
  MyType=array [1..20] of array [1..30] of integer;  {SAME}
var
  MyVar:^Mytype;     {^}
begin
new(MyVar);       {Allocate space on the heap}
...
MyVar^[i][j]:=1;   {note the "^"}
...

Note that each SEPARATE array (of array) anyway can't exceed 64k (there are
also workarounds, but I hope you don't need it :-)

By the way, "array[1..20] of array [1..30] of integer" (lots of arrays of
arrays of arrays...) is same as "array[1..20,1..30] of integer".

Sandman4
-------
http://sandman4.cjb.net
CC's greatly appreciated (poor news server).

Other Threads