Board index » delphi » I need help: Data Segment Too Large message

I need help: Data Segment Too Large message

I'm  converting an old dBASE program to Delphi 1.
After adding the last two forms to my program, I'm now getting a
        Data Segment Too Large      error message.

It seems that all of the forms are created in the DPR.  Are they
grabbing memory?  I thought that Delphi grabbed memory when
the form became active through SHOW or SHOWMODAL.  Then
it would free memory when exiting the form.

The old dBASE program was huge.  I had to use segmentation
and overlays in order to keep the program at a reasonable size.

Is there something that I should be doing in Delphi that I'm missing?

Can I create the forms from the main menu program and then
destroy or free when coming back from the form?  Will that
slow down the speed of the program?

I'm listing the DPR below.   Any help is really appreciated
because this is an area of DELPHI and Windows that I do
not understand.

thanks,
Bill Wester

program Sps;

uses
  Forms,
  Spsopen in 'SPSOPEN.PAS' {spsstart},
  Spsabout in 'SPSABOUT.PAS' {AboutBox},
  Stchreg in 'STCHREG.PAS' {TchReg},
  Stchlabl in 'STCHLABL.PAS' {TchLabel},
  Tlprint in 'TLPRINT.PAS' {TLabPrnt},
  Stchrolo in 'STCHROLO.PAS' {TchRolo},
  Trprint in 'TRPRINT.PAS' {TRolPrnt},
  Stchrng1 in 'STCHRNG1.PAS' {TchRang1},
  Stchrept in 'STCHREPT.PAS' {TchRept},
  Sgrmschd in 'SGRMSCHD.PAS' {GRmSchd},
  Tgprint in 'TGPRINT.PAS' {TSchdGRM},
  Stchschd in 'STCHSCHD.PAS' {TchSchd},
  Ttprint in 'TTPRINT.PAS' {TSchdTCH},
  Stextbk in 'STEXTBK.PAS' {TextBk},
  Stchcoor in 'STCHCOOR.PAS' {TchCoord},
  Stcheval in 'STCHEVAL.PAS' {TchEval},
  Teprint in 'TEPRINT.PAS' {TEvlPrnt},
  Stchexp in 'STCHEXP.PAS' {TchExp},
  Stchprof in 'STCHPROF.PAS' {TchProf},
  Tpprint in 'TPPRINT.PAS' {TProPrnt},
  Stchrng2 in 'STCHRNG2.PAS' {TchRang2},
  Sstureg in 'SSTUREG.PAS' {StuReg},
  Sstulabl in 'SSTULABL.PAS' {StuLabel},
  Slprint in 'SLPRINT.PAS' {SLabPrnt},
  Ssturolo in 'SSTUROLO.PAS' {StuRolo},
  Srprint in 'SRPRINT.PAS' {SRolPrnt},
  Namerang in 'NAMERANG.PAS' {StuRang1},
  Sstuattd in 'SSTUATTD.PAS' {StuAttend},
  Scprint in 'SCPRINT.PAS' {SCrdPrnt},
  Birthlis in 'BIRTHLIS.PAS' {Birthday},
  Sbprint in 'SBPRINT.PAS' {SBrthPrnt},
  Sstualph in 'SSTUALPH.PAS' {StuAlph},
  Saprint in 'SAPRINT.PAS' {SAlphPrt},
  Ssturoom in 'SSTUROOM.PAS' {StuRoom},
  Sregform in 'SREGFORM.PAS' {RegForm},
  Sfprint in 'SFPRINT.PAS' {SFrmPrnt},
  Namerng2 in 'NAMERNG2.PAS' {StuRang2},
  Srmname in 'SRMNAME.PAS' {RmByName},
  Srmsex in 'SRMSEX.PAS' {RmBySex},
  Sstudir in 'SSTUDIR.PAS' {StuDir},
  Stuiacct in 'STUIACCT.PAS' {TuAcct},
  Studaily in 'STUDAILY.PAS' {TuDaily},
  Sacctbal in 'SACCTBAL.PAS' {TuBalance},
  Stupay in 'STUPAY.PAS' {TuPayment},
  Stuchrg in 'STUCHRG.PAS' {TuCharge},
  Userinfo in 'USERINFO.PAS' {UserForm},
  Uindex in 'UINDEX.PAS' {UtilIndex},
  Setinfo in 'SETINFO.PAS' {SchlInfoDlg},
  Shomerm in 'SHOMERM.PAS' {HomeRoomList},
  Shprint in 'SHPRINT.PAS' {SLisPrnt};
{$R *.RES}

begin
  Application.CreateForm(Tspsstart, spsstart);
  Application.CreateForm(TAboutBox, AboutBox);
  Application.CreateForm(TTchReg, TchReg);
  Application.CreateForm(TStuReg, StuReg);
  Application.CreateForm(TTchRept, TchRept);
  Application.CreateForm(TGRmSchd, GRmSchd);
  Application.CreateForm(TTextBk, TextBk);
  Application.CreateForm(TTchCoord, TchCoord);
  Application.CreateForm(TTchEval, TchEval);
  Application.CreateForm(TStuLabel, StuLabel);
  Application.CreateForm(TSLabPrnt, SLabPrnt);
  Application.CreateForm(TStuAttend, StuAttend);
  Application.CreateForm(TStuRolo, StuRolo);
  Application.CreateForm(TStuRang1, StuRang1);
  Application.CreateForm(TTchRolo, TchRolo);
  Application.CreateForm(TTchRang1, TchRang1);
  Application.CreateForm(TTchLabel, TchLabel);
  Application.CreateForm(TBirthday, Birthday);
  Application.CreateForm(TSCrdPrnt, SCrdPrnt);
  Application.CreateForm(TSRolPrnt, SRolPrnt);
  Application.CreateForm(TTRolPrnt, TRolPrnt);
  Application.CreateForm(TTSchdTCH, TSchdTCH);
  Application.CreateForm(TStuAlph, StuAlph);
  Application.CreateForm(TSAlphPrt, SAlphPrt);
  Application.CreateForm(TStuRoom, StuRoom);
  Application.CreateForm(TUtilIndex, UtilIndex);
  Application.CreateForm(TTchExp, TchExp);
  Application.CreateForm(TRegForm, RegForm);
  Application.CreateForm(TSFrmPrnt, SFrmPrnt);
  Application.CreateForm(TStuRang2, StuRang2);
  Application.CreateForm(TRmByName, RmByName);
  Application.CreateForm(TRmBySex, RmBySex);
  Application.CreateForm(TStuDir, StuDir);
  Application.CreateForm(TTuAcct, TuAcct);
  Application.CreateForm(TTuDaily, TuDaily);
  Application.CreateForm(TTuBalance, TuBalance);
  Application.CreateForm(TTuPayment, TuPayment);
  Application.CreateForm(TTuCharge, TuCharge);
  Application.CreateForm(TTLabPrnt, TLabPrnt);
  Application.CreateForm(TUserForm, UserForm);
  Application.CreateForm(TSchlInfoDlg, SchlInfoDlg);
  Application.CreateForm(TTEvlPrnt, TEvlPrnt);
  Application.CreateForm(TSBrthPrnt, SBrthPrnt);
  Application.CreateForm(TTchProf, TchProf);
  Application.CreateForm(TTchRang2, TchRang2);
  Application.CreateForm(TTProPrnt, TProPrnt);
  Application.CreateForm(TTchSchd, TchSchd);
  Application.CreateForm(TTSchdTCH, TSchdTCH);
  Application.CreateForm(THomeRoomList, HomeRoomList);
  Application.CreateForm(TSLisPrnt, SLisPrnt);
  Application.Run;
end.

 

Re:I need help: Data Segment Too Large message


Quote
In article <6l7d1r$2k...@winter.news.erols.com>, bwes...@erols.com (bill wester) wrote:
>I'm  converting an old dBASE program to Delphi 1.
>After adding the last two forms to my program, I'm now getting a
>        Data Segment Too Large      error message.
>It seems that all of the forms are created in the DPR.  Are they
>grabbing memory?  I thought that Delphi grabbed memory when
>the form became active through SHOW or SHOWMODAL.  Then
>it would free memory when exiting the form.

*smile* Yes, they *are* grabbing memory - that .CreateForm calls actually set
up the forms in the first place.

Quote
>The old dBASE program was huge.  I had to use segmentation
>and overlays in order to keep the program at a reasonable size.
>Is there something that I should be doing in Delphi that I'm missing?
>Can I create the forms from the main menu program and then
>destroy or free when coming back from the form?  Will that
>slow down the speed of the program?

The impact on the speed of the program is pretty negligible if you couple it
with something in the user interface like a mouse click.  Right now, all the
forms are being created en masse at the beginning of your program.

I can't quite remember is this stuff was in the same spot back in D1, but if
you go into your project options, one of the tabs will show you two columns,
one with the auto-create forms, the other with 'available forms'.

Anything moved to the 'available forms' column will NOT be created until you
need it.  My suggestion would be to move pretty much everything you bring up
with .ShowModal to the available forms column.

Then, when you need to call the dialog/form/what have you, do something like
this:

  MyForm := TMyForm.Create(Application);
  try
    MyForm.ShowModal
  finally
    MyForm.Free;
  end;

(Of course, put in a little more code than that if you're expecting results
there)

It's a helpful technique, but it still probably doesn't explain your Data
Segment too Large error.  What that error indicates, typically, is that you
have more than 64K of global variables of some sort.  The usual culprits are
arrays that 'never *looked* that big' - multidimensional arrays (especially of
something like strings) can take up inordinate amounts of memory.

I'd take a look for those, first.  If you can't find a way around using those,
perhaps we can help (there's plenty of dynamic allocation methods for things
like that)

Hope that helps..

  --=- Ritchie Annand

Re:I need help: Data Segment Too Large message


In article <6l7d1r$2k...@winter.news.erols.com>

Quote
bwes...@erols.com (bill wester) wrote:
> I'm  converting an old dBASE program to Delphi 1.
> After adding the last two forms to my program, I'm now getting a
>    Data Segment Too Large      error message.

> It seems that all of the forms are created in the DPR.  Are they
> grabbing memory?  I thought that Delphi grabbed memory when
> the form became active through SHOW or SHOWMODAL.  Then
> it would free memory when exiting the form.

This has nothing to do with your data segment being too large.

Quote
> The old dBASE program was huge.  I had to use segmentation
> and overlays in order to keep the program at a reasonable size.

Like I said in a previous mail, you need to use dynamic data
structures. You might want to do this even with strings. A single
string can take 256 bytes of memory in your data segment.
Using a pointer to a string takes 4 bytes in your data segment,
and then you can allocate and free memory for it on the fly.
If you have a lot of strings, then that is the first thing to look at.
The second thing is all your RECORDs (for your headers
and data, et al). Instead of declaring static variables for
your records, use pointers.

Something else you might want to do is to encapsulate the
larger data structures in a Class. Since Classes are allocated
on the heap, this might solve your problem with the data
segment.

Best regards, The Chief
--------
Dr. A{*word*73}la A. Olowofoyeku (The African Chief)
Email: la...@keele.ac.uk
Homepage: http://ourworld.compuserve.com/homepages/African_Chief/
Author of: Chief's Installer Pro v4.25 for Win16 and Win32:
ftp://ftp.demon.co.uk/pub/ibmpc/win3/apps/chief/pro/chief425.zip

Re:I need help: Data Segment Too Large message


On Fri, 05 Jun 1998 00:05:48 GMT, bwes...@erols.com (bill wester)
wrote:

Quote
>I'm  converting an old dBASE program to Delphi 1.
>After adding the last two forms to my program, I'm now getting a
>    Data Segment Too Large      error message.

>It seems that all of the forms are created in the DPR.  Are they
>grabbing memory?  

In general, yes

Quote
> I thought that Delphi grabbed memory when
>the form became active through SHOW or SHOWMODAL.  Then
>it would free memory when exiting the form.

>The old dBASE program was huge.  I had to use segmentation
>and overlays in order to keep the program at a reasonable size.

>Is there something that I should be doing in Delphi that I'm missing?

Well, one thing that might help solve your problems is trying to move
your global data as much as possible to the heap. What you should look
for are any global variables (maybe also local variables in units)
that seem large, such as (large) arrays and/or (short) strings. Many
record variables also come in this category. Common techniques are
creating pointers to records, strings or arrays, instead of direct
allocation to a variable.

Quote

>Can I create the forms from the main menu program and then
>destroy or free when coming back from the form?  Will that
>slow down the speed of the program?

yes and possibly yes.

Look at the Project options (view-project manager-> options) to select
whether to create forms automatically or by progam control (look for
the help on this). Don't know whether this would help, depends
entirely on the code that each form class contains. I suspect though
that the memory is not eaten by the forms, but by something else.

hth
David

Quote

>I'm listing the DPR below.   Any help is really appreciated
>because this is an area of DELPHI and Windows that I do
>not understand.
>thanks,
>Bill Wester

>program Sps;

>uses
>  Forms,
>  Spsopen in 'SPSOPEN.PAS' {spsstart},
>  Spsabout in 'SPSABOUT.PAS' {AboutBox},
>  Stchreg in 'STCHREG.PAS' {TchReg},
>  Stchlabl in 'STCHLABL.PAS' {TchLabel},
>  Tlprint in 'TLPRINT.PAS' {TLabPrnt},
>  Stchrolo in 'STCHROLO.PAS' {TchRolo},
>  Trprint in 'TRPRINT.PAS' {TRolPrnt},
>  Stchrng1 in 'STCHRNG1.PAS' {TchRang1},
>  Stchrept in 'STCHREPT.PAS' {TchRept},
>  Sgrmschd in 'SGRMSCHD.PAS' {GRmSchd},
>  Tgprint in 'TGPRINT.PAS' {TSchdGRM},
>  Stchschd in 'STCHSCHD.PAS' {TchSchd},
>  Ttprint in 'TTPRINT.PAS' {TSchdTCH},
>  Stextbk in 'STEXTBK.PAS' {TextBk},
>  Stchcoor in 'STCHCOOR.PAS' {TchCoord},
>  Stcheval in 'STCHEVAL.PAS' {TchEval},
>  Teprint in 'TEPRINT.PAS' {TEvlPrnt},
>  Stchexp in 'STCHEXP.PAS' {TchExp},
>  Stchprof in 'STCHPROF.PAS' {TchProf},
>  Tpprint in 'TPPRINT.PAS' {TProPrnt},
>  Stchrng2 in 'STCHRNG2.PAS' {TchRang2},
>  Sstureg in 'SSTUREG.PAS' {StuReg},
>  Sstulabl in 'SSTULABL.PAS' {StuLabel},
>  Slprint in 'SLPRINT.PAS' {SLabPrnt},
>  Ssturolo in 'SSTUROLO.PAS' {StuRolo},
>  Srprint in 'SRPRINT.PAS' {SRolPrnt},
>  Namerang in 'NAMERANG.PAS' {StuRang1},
>  Sstuattd in 'SSTUATTD.PAS' {StuAttend},
>  Scprint in 'SCPRINT.PAS' {SCrdPrnt},
>  Birthlis in 'BIRTHLIS.PAS' {Birthday},
>  Sbprint in 'SBPRINT.PAS' {SBrthPrnt},
>  Sstualph in 'SSTUALPH.PAS' {StuAlph},
>  Saprint in 'SAPRINT.PAS' {SAlphPrt},
>  Ssturoom in 'SSTUROOM.PAS' {StuRoom},
>  Sregform in 'SREGFORM.PAS' {RegForm},
>  Sfprint in 'SFPRINT.PAS' {SFrmPrnt},
>  Namerng2 in 'NAMERNG2.PAS' {StuRang2},
>  Srmname in 'SRMNAME.PAS' {RmByName},
>  Srmsex in 'SRMSEX.PAS' {RmBySex},
>  Sstudir in 'SSTUDIR.PAS' {StuDir},
>  Stuiacct in 'STUIACCT.PAS' {TuAcct},
>  Studaily in 'STUDAILY.PAS' {TuDaily},
>  Sacctbal in 'SACCTBAL.PAS' {TuBalance},
>  Stupay in 'STUPAY.PAS' {TuPayment},
>  Stuchrg in 'STUCHRG.PAS' {TuCharge},
>  Userinfo in 'USERINFO.PAS' {UserForm},
>  Uindex in 'UINDEX.PAS' {UtilIndex},
>  Setinfo in 'SETINFO.PAS' {SchlInfoDlg},
>  Shomerm in 'SHOMERM.PAS' {HomeRoomList},
>  Shprint in 'SHPRINT.PAS' {SLisPrnt};
>{$R *.RES}

>begin
>  Application.CreateForm(Tspsstart, spsstart);
>  Application.CreateForm(TAboutBox, AboutBox);
>  Application.CreateForm(TTchReg, TchReg);
>  Application.CreateForm(TStuReg, StuReg);
>  Application.CreateForm(TTchRept, TchRept);
>  Application.CreateForm(TGRmSchd, GRmSchd);
>  Application.CreateForm(TTextBk, TextBk);
>  Application.CreateForm(TTchCoord, TchCoord);
>  Application.CreateForm(TTchEval, TchEval);
>  Application.CreateForm(TStuLabel, StuLabel);
>  Application.CreateForm(TSLabPrnt, SLabPrnt);
>  Application.CreateForm(TStuAttend, StuAttend);
>  Application.CreateForm(TStuRolo, StuRolo);
>  Application.CreateForm(TStuRang1, StuRang1);
>  Application.CreateForm(TTchRolo, TchRolo);
>  Application.CreateForm(TTchRang1, TchRang1);
>  Application.CreateForm(TTchLabel, TchLabel);
>  Application.CreateForm(TBirthday, Birthday);
>  Application.CreateForm(TSCrdPrnt, SCrdPrnt);
>  Application.CreateForm(TSRolPrnt, SRolPrnt);
>  Application.CreateForm(TTRolPrnt, TRolPrnt);
>  Application.CreateForm(TTSchdTCH, TSchdTCH);
>  Application.CreateForm(TStuAlph, StuAlph);
>  Application.CreateForm(TSAlphPrt, SAlphPrt);
>  Application.CreateForm(TStuRoom, StuRoom);
>  Application.CreateForm(TUtilIndex, UtilIndex);
>  Application.CreateForm(TTchExp, TchExp);
>  Application.CreateForm(TRegForm, RegForm);
>  Application.CreateForm(TSFrmPrnt, SFrmPrnt);
>  Application.CreateForm(TStuRang2, StuRang2);
>  Application.CreateForm(TRmByName, RmByName);
>  Application.CreateForm(TRmBySex, RmBySex);
>  Application.CreateForm(TStuDir, StuDir);
>  Application.CreateForm(TTuAcct, TuAcct);
>  Application.CreateForm(TTuDaily, TuDaily);
>  Application.CreateForm(TTuBalance, TuBalance);
>  Application.CreateForm(TTuPayment, TuPayment);
>  Application.CreateForm(TTuCharge, TuCharge);
>  Application.CreateForm(TTLabPrnt, TLabPrnt);
>  Application.CreateForm(TUserForm, UserForm);
>  Application.CreateForm(TSchlInfoDlg, SchlInfoDlg);
>  Application.CreateForm(TTEvlPrnt, TEvlPrnt);
>  Application.CreateForm(TSBrthPrnt, SBrthPrnt);
>  Application.CreateForm(TTchProf, TchProf);
>  Application.CreateForm(TTchRang2, TchRang2);
>  Application.CreateForm(TTProPrnt, TProPrnt);
>  Application.CreateForm(TTchSchd, TchSchd);
>  Application.CreateForm(TTSchdTCH, TSchdTCH);
>  Application.CreateForm(THomeRoomList, HomeRoomList);
>  Application.CreateForm(TSLisPrnt, SLisPrnt);
>  Application.Run;
>end.

------------------
David A. Schweizer

iec ProGAMMA, The Netherlands
d.a.schweizer[OK, i don't want any more spam]gamma.rug.nl
guess where the '@' goes ?

Re:I need help: Data Segment Too Large message


Bill,

I answered an earlier post in which you didn't provide as much
code.

[SNIP]

Quote
>   Application.CreateForm(Tspsstart, spsstart);
>   Application.CreateForm(TAboutBox, AboutBox);
[SNIP]
>   Application.CreateForm(TTSchdTCH, TSchdTCH);
>   Application.CreateForm(THomeRoomList, HomeRoomList);
>   Application.CreateForm(TSLisPrnt, SLisPrnt);
>   Application.Run;
> end.

Your problem is simple - you're allowing Delphi to autocreate
all of these forms! That means that a) your app _has_ to be
taking forever to load, even on a fast machine; and b) you're
eating major chunks of memory in one fell swoop!

You need to remove most (if not all) of the forms except your
app's main form and create them only as needed (eg., in
response to a menu click). Also, in each form's OnClose event
handler, you need to use 'Action := caFree' as the last line
to release the memory back to your app.

This will almost immediately solve your data segment problem,
and will dramatically improve the performance of your app.

HTH

Ken
--
Ken White
kwh...@westelcom.com

Clipper Functions for Delphi
http://members.aol.com/clipfunc/

Other Threads