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
Steve Hiscock -- SD Technologies

EMail: shisc...@atcon.com
BBS  : under construction

 

Re:Data Segment to Large


Quote
In article <4c034n$...@thor.atcon.com> shisc...@MAIL.ATCON.COM (Steve Hiscock) writes:
>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.

You need to allocate the larger data structures dynamically, e.g. with "new,"
and reference them through pointers.  In Delphi you can simply create a class,
create an instance of that class, and dispense with all those silly "^s."

/mr/

Re:Data Segment to Large


Quote
You 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.

Yes, you have too much *static* data in your data segment.  For some of
your big structures, allocate the memory on the heap using *new* and free
it using *dispose* when you are done.  Get Rubenking's book if you need to
handle big data structures.

Re:Data Segment to Large


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

This is probably in the FAQ list, but still, you need to make some of
your data structures dynamically allocated. See the on-line Help under
the keywords "New" and "GetMem".

Regards,

Jani Jarvinen
jani.jrvi...@hitec.fipnet.fi

---
Check out Help Editor 2.0 for Windows, the most powerful program to
create Windows Help files:
ftp://ftp.mpoli.fi/metropoli/windows/utils/hlped20.zip
---
 * SLMR 2.1a *

Re:Data Segment to Large


Quote
> >is possible to make bigger programs in pascal, but how is the
> >question?  Please help me!  

Pointers. <---- Thats it. They'll work.

With pointers you can actually use your physical memory, going way beyond
the 64k data structure. [yr still limited by 640k though]

Re:Data Segment to Large


Hello Steve!

 SH> @RFC.Gate: Fri, 29 Dec 95 19:56:13

 SH> From: shisc...@MAIL.ATCON.COM (Steve Hiscock)

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

If you use an array like

Quote
>VAR
>  FooBar            : ARRAY[1..40000]OF CHAR;

you'd be better off doing this:

Quote
>TYPE
>  Pchar             = ^CHAR;
>  PFooBarType       = ARRAY[1..40000]OF Pchar;
>VAR
>  FooBar            : PFooBarType;

Then you'd not use the same way of adressing the data in the array.

Quote
>  FooBar[1]:='A';

is no longer possible

Quote
>  FooBar[1]^:='A';

is.

Also before using any of the chars in such an array you have to claim it from
the HEAP.

Quote
>  NEW(FooBar[no]);

Before you close you program, it is a good custum to give back the areas you
took from the HEAP this the DISPOSE command instead of NEW.

Now you can access (in TP) the leftover area below 640KB not used by other
programs. (remember to set your {$M} or IDE compiler setting to how much you
want to reserve for you heap and how much should be present or your programs
will not function.

For example you could work with 2 x 64000bytes for a small paintprogram
editing, whereas having 4x64000 bytes would enable the user ofthe program to
switch back to before using a brush on the screen.

If at any time memory is too limited you can create a file of disk and put
items into, then deallocate with DISPOSE and you have more memory. Or you can
use the BP compiler in protected mode and use XMS memory up to 16mb (minus
memory taken by already running programs).

The key you see, is to use dynamic variables instead of variables known at
compile time. You can use 10kb for names or adresses or phonenumbers if you
have 10kb of each, you will be able to have all of one set in your memory and
sort them but not all 3 kind of elements at once. After sorting them youcan use
the same area for an image or something else.

Also using allocated memory via NEW and DISPOSE is better when dealing with
large amounts of data like say 50 bytes x 500 and you want to sort them. With a
bubblesort algorithm it will take forever to move them into a sorted order, but
with an ARRAY of pointers to the data area, you only exchange the pointers and
that's always just 4 bytes - regardless of the amount of bytes they point to.

Regards
Mikkel Breiler

Other Threads