Board index » delphi » Data Segment to Large

Data Segment to Large

Okay.  I am working on a rather large program right now, and I am
having some problems with running it.  It seems that the "Data Segment
is to Large" according to the compiler.  I am aware of what the
problem is, but what I am unsure of is how to fix it.  I know that it
is possible to make bigger programs in pascal, but how is the
question?  Please help me!  This is very urgent.

Steve...  Reply here or via email at...  shisc...@atcon.com

 

Re:Data Segment to Large


Quote
Superius! (super...@superior.net) wrote:
> Okay.  I am working on a rather large program right now, and I am
> having some problems with running it.  It seems that the "Data Segment
> is to Large" according to the compiler.  I am aware of what the
> problem is, but what I am unsure of is how to fix it.  I know that it
> is possible to make bigger programs in pascal, but how is the
> question?  Please help me!  This is very urgent.

A) Use the heap.  This involves learning about pointers and
assigning heap memory to pointers with the NEW procedure.  Then
instead of referring to x as a variable, you use x^ as the variable
pointed at by the pointer x.  Check the sample programs for
examples.

b) Make your variables smaller - use singles instead of doubles or
extended reals.

c) Store infrequently referenced data arrays as records in disk
files.

d) Shrink the buffers on text files.

etc. etc.  Mostly use the heap.

David Emanuel

Re:Data Segment to Large


Quote
super...@superior.net (Superius!) wrote:
>Okay.  I am working on a rather large program right now, and I am
>having some problems with running it.  It seems that the "Data Segment
>is to Large" according to the compiler.  I am aware of what the
>problem is, but what I am unsure of is how to fix it.  I know that it
>is possible to make bigger programs in pascal, but how is the
>question?  Please help me!  This is very urgent.
>Steve...  Reply here or via email at...  shisc...@atcon.com

Your problem is that you are using too many / too large global
variables. Variables that take up a lot of space are ARRAYS and
STRINGS.

A simple string takes up 256 bytes (255 for the contents, 1 for the
length counter).  This is 1/4 of a Kilobyte, which means that your
data segment can only contain 256 of these {*word*81}s....

Now usually a string needn't contain more than about 80 characters (a
full screen's width in text mode). So, wherever possible, replace  

"VAR a:String"  with "VAR a:String[80]" and you'll save HUNDREDS of
bytes per string.

Next, try to move all variables that you DON'T NEED GLOBALLY  into
your procedures. Make them local! These variables are not inside your
data segment, but on the stack, and available ONLYonly inside the
procedure where they were declared, and they are destroyed as soon as
you leave the procedure.

So instead of:

VAR s:array[1..1000] of char;

procedure test;
begin
s[1]:='t';
end;

Use:

procedure test;
VAR s:array[1..1000] of char;
begin
s[1]:='t';
end;

These tips are the easiest way to save memory, without resorting to
pointer variables on the heap. If you want to find out how much data
memory your program needs, use [C]ompile [I]nfo in Borland Pascal
after you compiled your program.

Hope this helps,
Arthur Hoornweg.

Arthur Hoornweg
(art...@geology.aball.de)

Re:Data Segment to Large


For any arrays that you define, put 'em on the heap.

Type
  PMyArray=^TMyArray;
  TMyArray=Array[1..399] Of Long;

Var
  MyPtr : PMyArray;

Begin
  New(MyPtr);
  MyPtr^[1] := 45345;
  Writeln('I just stored ', MyPtr^[1], ' on the heap.');
End.

Also, put any strings you want to use in a text file, one per line.  Then,
when you initialize your program, read this text file into a structure
similar to the one above.  When you want to write a string, refer to the
string by varible name and array index (e.g., MyString^[234] would contain
line 234 of the text file).

If you do this, however, bear in mind that using New() on a String type
will always allocate 256 bytes.  If you want to allocate fewer bytes per
string, create a pointer to a string and an array of pointers to strings.
Then, create a procedure to assign a string value to one of these
pointers:

(Suppose the following line is the contents of your string file:)
This is a string on the heap.

Program HeapStr;

Type
  PMyString=^String;
  PMyArray=^TMyArray;
  TMyArray=Array[1..500] Of PMyString;

Procedure AssignString(sp : PMyString; sv : String);
Begin
  GetMem(sp, Length(sv)+1);
  sp^ := sv;
End;

Var
  MyPtr : PMyArray;
  F : Text;
  Tmp : String;
  i : Word;

Begin
  Assign(F,'STRINGS.TXT');
  Reset(F);
  New(MyPtr);
  i := 0;
  While Not EOF(F) Do Begin
    Inc(i);
    ReadLn(F, Tmp);
    AssignString(MyPtr^[i],Tmp);
  End;
  Close(F);
  WriteLn(MyPtr^[1]);
End.

This program would output:

This is a string on the heap.

Re:Data Segment to Large


In article <4dovqq$...@thor.atcon.com>,
   super...@superior.net (Superius!) wrote:

Quote
>Okay.  I am working on a rather large program right now, and I am
>having some problems with running it.  It seems that the "Data Segment
>is to Large" according to the compiler.  I am aware of what the
>problem is, but what I am unsure of is how to fix it.  I know that it
>is possible to make bigger programs in pascal, but how is the
>question?  Please help me!  This is very urgent.

The first step would be to go through your code and change any large arrays to
pointers to those arrays. Allocate the memory for them rather having them
static in memory. A pointer only takes eight bytes as opposed to a bunch of
memory being taken up by a static array.

-----------------------------------------------
Mike Chapin
Powder River
mcha...@vcn.com
http://www.vcn.com/server/netizens/mchapin/first.html
Gillette, WY

Not the end of the earth but you can see it from
there.
-----------------------------------------------

Other Threads