Board index » delphi » data segment too large?

data segment too large?

hi
when compiling my program (see below) i get a strange error that i have
never encountered before. this is probably because i have never really
written any substancial sized programs, but i wouldnt call the program below
large!
the error is:

C:\TP>tpc filecrea
Turbo Pascal Version 5.5  Copyright (c) 1983,89 Borland International
FILECREA.PAS(125): Error 49: Data segment too large.
end.
   ^

i get the same error when compiling in the ide.

the program is part of a project, where i have to create a program to commit
a binary search on a file to find a town, and then show it distance from
london. i havent finished it yet, but this is what i have done so far. i
would not like anyone to do anything more for me, but if someone could
please tell me what this error means and how i could fix it, i would be
seriosly gratefull!!
in my code i have included a validation module (the procedure
validate(string) ) which i have created using the help from people in this
newsgroup! thank you! sorry the code is sooo bitty though, i havent really
had time to sort it out, and the indenting has went all wierd because my
news program (outlook express) doesnt support the one space per character
format :o(

By the way, I don't know if this matters... but i use TP 5.5 on 333MHz AMD
K6-2 with 64 megs of RAM. I have a feeling that this problem could be
something to do with MS-DOS allocated memory?

thanx

craig

code:

program stringint;

uses crt;

type town_records = record
     town : string;
     distance : integer
     end;

type towns_array = array[1..250] of town_records;

var integerstring2 : string;
    validint       : integer;
    temparray      : towns_array;
    filename       : string;
    file1          : file of towns_array;
    userchoice     : string;
    continue       : boolean;

procedure validate(integerstring : string);

var error         : integer;
    continue      : boolean;
    count         : integer;

begin
   count := 0;
   validint := 0;
   repeat
      count := count + 1;
      clrscr;
      if count > 1 then
         begin
            clrscr;
            write('INPUT INTEGER : ');
            readln(integerstring);
         end;
      val(integerstring,validint,error);
      if error = 0 then
         continue := true;
      if error <> 0 then
         begin
            clrscr;
            writeln('THIS IS NOT A VALID VALUE!');
            readln;
            continue := false;
         end;
   until continue = true;
end;

procedure viewhelp;

begin
   clrscr;
   writeln('THIS PROGRAM IS MENU DRIVEN. CHOOSE A CHOICE WHEN CONFRONTED
WITH ONE.');
   writeln;
   writeln('PRESS ENTER TO REURN TO THE MENU');
   readln;
end;

procedure createfile;

var townuserinput     : string;
    distanceuserinput : string;
    validtowninput    : integer;

begin
   clrscr;
   write('INPUT TOWN [ZZ TO EXIT] : ');
   readln(townuserinput);
   while (townuserinput <> 'zz') and (townuserinput <> 'ZZ') and
         (townuserinput <> 'Zz') and (townuserinput <> 'zZ') do
      begin
         write('INPUT DISTANCE FROM LONDON');
         readln(distanceuserinput);
         validate(distanceuserinput);
         validtowninput := validint;
         clrscr;
         write('INPUT TOWN [ZZ TO EXIT] : ');
         readln(townuserinput);
      end;
end;

begin
   repeat
      clrscr;
      continue := true;
      gotoxy(5,3);
      write('1. CREATE NEW FILE');
      gotoxy(5,4);
      write('2. VIEW HELP FILE');
      gotoxy(5,5);
      write('3. EXIT');
      gotoxy(5,7);
      write('ENTER CHOICE : ');
      readln(userchoice);
      if userchoice = '1' then
         createfile;
      if userchoice = '2' then
         viewhelp;
      if userchoice = '3' then
         continue := false;
      if (userchoice <> '1') and (userchoice <> '2') and (userchoice <> '3')
then
         begin
            clrscr;
            continue := true;
            writeln('THE CHOICE ENTERED WAS NOT A VALID CHOICE');
            readln;
         end;
   until continue = false;
end.

 

Re:data segment too large?


Quote
Craig Hennessey <cdhennes...@freenetname.co.uk> wrote:
> FILECREA.PAS(125): Error 49: Data segment too large.
> program stringint;
> uses crt;
> type town_records = record
>      town : string;
>      distance : integer
>      end;
> type towns_array = array[1..250] of town_records;
> var integerstring2 : string;
>     validint       : integer;
>     temparray      : towns_array;
>     filename       : string;
>     file1          : file of towns_array;
>     userchoice     : string;
>     continue       : boolean;

Your main problem is the variable temparray. The town_records type occupies
258 bytes, so temparray occupies 250*258 = 64500 bytes in the data segment,
which has a maximum size of 64KB = 65536 bytes. (Actually it may be a little
less that is allowed). With your other variables you are going over this
limit.

The easiest way to fix this is to use shorter strings. Do you really need up
to 255 characters for the name of the town? If 40 characters will do, you
will save 52KB or so (53500 bytes) simply by modifying the declaration of
town_records as

type town_records = record
     town: string[40];
     distance: integer;
     end;

and the problem will disappear.

If you do need long strings, you are going to have to use pointers and put
this on the heap. But I think it is very unlikely that you will need to do
that.

--
______________________________________________________________________
     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?


Quote
Craig Hennessey <cdhennes...@freenetname.co.uk> wrote:

: hi
: when compiling my program (see below) i get a strange error that i have
: never encountered before. this is probably because i have never really
: written any substancial sized programs, but i wouldnt call the program below
: large!
[snip]

: program stringint;

: uses crt;

: type town_records = record
:      town : string;
:      distance : integer
:      end;

a string declared without a maximum size (e.g. "town: string[20]") is
given a size of 255 (thus 256 bytes with length byte).  a TP integer is 2
bytes.

: type towns_array = array[1..250] of town_records;

any variables using this type will be 258*250=64500 bytes in size.

: var integerstring2 : string;                <----  256 bytes
:     validint       : integer;               <----- 2 bytes
:     temparray      : towns_array;           <----- 64500 bytes
:     filename       : string;                <----- 256 bytes
:     file1          : file of towns_array;   <-- dunno
:     userchoice     : string;                <----  256 bytes
:     continue       : boolean;               <--- 1 byte, iirc

This puts you at 65271 bytes used so far.  now according to TP help, the
maximum size of a program's data segment is 65520 bytes, including data
declared by used units (i.e. crt)

i'd advise specifying a maximum length for your strings (can't imagine
'town' needing anywhere near 255 characters) and/or declaring larger
structures dynamically on the heap.  lemme know if you need help on that..

assas...@reality.halo.nu

: procedure validate(integerstring : string);

: var error         : integer;
:     continue      : boolean;
:     count         : integer;

: begin
:    count := 0;
:    validint := 0;
:    repeat
:       count := count + 1;
:       clrscr;
:       if count > 1 then
:          begin
:             clrscr;
:             write('INPUT INTEGER : ');
:             readln(integerstring);
:          end;
:       val(integerstring,validint,error);
:       if error = 0 then
:          continue := true;
:       if error <> 0 then
:          begin
:             clrscr;
:             writeln('THIS IS NOT A VALID VALUE!');
:             readln;
:             continue := false;
:          end;
:    until continue = true;
: end;

: procedure viewhelp;

: begin
:    clrscr;
:    writeln('THIS PROGRAM IS MENU DRIVEN. CHOOSE A CHOICE WHEN CONFRONTED
: WITH ONE.');
:    writeln;
:    writeln('PRESS ENTER TO REURN TO THE MENU');
:    readln;
: end;

: procedure createfile;

: var townuserinput     : string;
:     distanceuserinput : string;
:     validtowninput    : integer;

: begin
:    clrscr;
:    write('INPUT TOWN [ZZ TO EXIT] : ');
:    readln(townuserinput);
:    while (townuserinput <> 'zz') and (townuserinput <> 'ZZ') and
:          (townuserinput <> 'Zz') and (townuserinput <> 'zZ') do
:       begin
:          write('INPUT DISTANCE FROM LONDON');
:          readln(distanceuserinput);
:          validate(distanceuserinput);
:          validtowninput := validint;
:          clrscr;
:          write('INPUT TOWN [ZZ TO EXIT] : ');
:          readln(townuserinput);
:       end;
: end;

: begin
:    repeat
:       clrscr;
:       continue := true;
:       gotoxy(5,3);
:       write('1. CREATE NEW FILE');
:       gotoxy(5,4);
:       write('2. VIEW HELP FILE');
:       gotoxy(5,5);
:       write('3. EXIT');
:       gotoxy(5,7);
:       write('ENTER CHOICE : ');
:       readln(userchoice);
:       if userchoice = '1' then
:          createfile;
:       if userchoice = '2' then
:          viewhelp;
:       if userchoice = '3' then
:          continue := false;
:       if (userchoice <> '1') and (userchoice <> '2') and (userchoice <> '3')
: then
:          begin
:             clrscr;
:             continue := true;
:             writeln('THE CHOICE ENTERED WAS NOT A VALID CHOICE');
:             readln;
:          end;
:    until continue = false;
: end.

Re:data segment too large?


In article <N9TK4.558$d21.66677@elnws01>,

Quote
Assassin  <assas...@reality.halo.nu> wrote:

>i'd advise specifying a maximum length for your strings (can't imagine
>'town' needing anywhere near 255 characters) and/or declaring larger
>structures dynamically on the heap.  lemme know if you need help on that..

If one allocates records with just one string from heap, an efficient
way is to put the string as the last field and the allocate only as much
as is needed:

 type Ttownrecord = record
         distance : integer
         town : string;
      end;
      Ptownrecord:Ttownrecord;

Function NewTown(t:string; dist:integer):Ptownrecord;
var p:Ptownrecord;
Begin
  getmem(p,sizeof(Ttownrecord)-255+length(t));
  p^.town:=t;
  p^.distance:=dist;
  NewTown:=p;
End;

Procedure disposeTown(p:Ptownrecord);
Begin
  freemem(p,sizeof(Townrecord)-255+length(p^.town));
End;

That way one allocates only as much as is actually needed for the
particular record.

Osmo

Re:data segment too large?


In article <N9TK4.558$d21.66677@elnws01>, Assassin says...

Quote

>Craig Hennessey <cdhennes...@freenetname.co.uk> wrote:
>: hi
>: when compiling my program (see below) i get a strange error that i have
>: never encountered before. this is probably because i have never really
>: written any substancial sized programs, but i wouldnt call the program below
>: large!
>[snip]

>: program stringint;

>: uses crt;

>: type town_records = record
>:      town : string;
>:      distance : integer
>:      end;

>a string declared without a maximum size (e.g. "town: string[20]") is
>given a size of 255 (thus 256 bytes with length byte).  a TP integer is 2
>bytes.

>: type towns_array = array[1..250] of town_records;

>any variables using this type will be 258*250=64500 bytes in size.

>: var integerstring2 : string;                <----  256 bytes
>:     validint       : integer;               <----- 2 bytes
>:     temparray      : towns_array;           <----- 64500 bytes
>:     filename       : string;                <----- 256 bytes
>:     file1          : file of towns_array;   <-- dunno
>:     userchoice     : string;                <----  256 bytes
>:     continue       : boolean;               <--- 1 byte, iirc

>This puts you at 65271 bytes used so far.  now according to TP help, the
>maximum size of a program's data segment is 65520 bytes, including data
>declared by used units (i.e. crt)

>i'd advise specifying a maximum length for your strings (can't imagine
>'town' needing anywhere near 255 characters) and/or declaring larger
>structures dynamically on the heap.  lemme know if you need help on that..

>assas...@reality.halo.nu

I'm waitin' for Stockton to jump your bones for not t{*word*220} the rest...

- Show quoted text -

Quote

>: procedure validate(integerstring : string);

>: var error         : integer;
>:     continue      : boolean;
>:     count         : integer;

>: begin
>:    count := 0;
>:    validint := 0;
>:    repeat
>:       count := count + 1;
>:       clrscr;
>:       if count > 1 then
>:          begin
>:             clrscr;
>:             write('INPUT INTEGER : ');
>:             readln(integerstring);
>:          end;
>:       val(integerstring,validint,error);
>:       if error = 0 then
>:          continue := true;
>:       if error <> 0 then
>:          begin
>:             clrscr;
>:             writeln('THIS IS NOT A VALID VALUE!');
>:             readln;
>:             continue := false;
>:          end;
>:    until continue = true;
>: end;

>: procedure viewhelp;

>: begin
>:    clrscr;
>:    writeln('THIS PROGRAM IS MENU DRIVEN. CHOOSE A CHOICE WHEN CONFRONTED
>: WITH ONE.');
>:    writeln;
>:    writeln('PRESS ENTER TO REURN TO THE MENU');
>:    readln;
>: end;

>: procedure createfile;

>: var townuserinput     : string;
>:     distanceuserinput : string;
>:     validtowninput    : integer;

>: begin
>:    clrscr;
>:    write('INPUT TOWN [ZZ TO EXIT] : ');
>:    readln(townuserinput);
>:    while (townuserinput <> 'zz') and (townuserinput <> 'ZZ') and
>:          (townuserinput <> 'Zz') and (townuserinput <> 'zZ') do
>:       begin
>:          write('INPUT DISTANCE FROM LONDON');
>:          readln(distanceuserinput);
>:          validate(distanceuserinput);
>:          validtowninput := validint;
>:          clrscr;
>:          write('INPUT TOWN [ZZ TO EXIT] : ');
>:          readln(townuserinput);
>:       end;
>: end;

>: begin
>:    repeat
>:       clrscr;
>:       continue := true;
>:       gotoxy(5,3);
>:       write('1. CREATE NEW FILE');
>:       gotoxy(5,4);
>:       write('2. VIEW HELP FILE');
>:       gotoxy(5,5);
>:       write('3. EXIT');
>:       gotoxy(5,7);
>:       write('ENTER CHOICE : ');
>:       readln(userchoice);
>:       if userchoice = '1' then
>:          createfile;
>:       if userchoice = '2' then
>:          viewhelp;
>:       if userchoice = '3' then
>:          continue := false;
>:       if (userchoice <> '1') and (userchoice <> '2') and (userchoice <> '3')
>: then
>:          begin
>:             clrscr;
>:             continue := true;
>:             writeln('THE CHOICE ENTERED WAS NOT A VALID CHOICE');
>:             readln;
>:          end;
>:    until continue = false;
>: end.

Re:data segment too large?


JRS:  In article <8dfs5s$be...@gxsn.com> of Mon, 17 Apr 2000 21:24:46
seen in news:comp.lang.pascal.borland, Craig Hennessey <cdhennessey@free

Quote
netname.co.uk> wrote:
>type town_records = record
>     town : string;
>     distance : integer
>     end;

>type towns_array = array[1..250] of town_records;

250*258 is large.

Quote

>var integerstring2 : string;
>    validint       : integer;
>    temparray      : towns_array;
>    filename       : string;
>    file1          : file of towns_array;
>    userchoice     : string;
>    continue       : boolean;

In TP7, BP7, &c., continue is already defined; it is unwise to change
it.  Use, perhaps, "proceed".

Quote
>   until continue = true;

until continue;  It's a boolean, an enumerated type of values (false,
true), and until looks for true.

Quote
>   write('INPUT TOWN [ZZ TO EXIT] : ');

[0 to exit] would be simpler; that's a zero.

Quote
>   readln(townuserinput);
>   while (townuserinput <> 'zz') and (townuserinput <> 'ZZ') and
>         (townuserinput <> 'Zz') and (townuserinput <> 'zZ') do

Cleaner to insist on ZZ, or to UpCase the first two characters.

Quote
>      if userchoice = '1' then
>         createfile;
>      if userchoice = '2' then
>         viewhelp;
>      if userchoice = '3' then
>         continue := false;
>      if (userchoice <> '1') and (userchoice <> '2') and (userchoice <> '3')
>then
>         begin
>            clrscr;
>            continue := true;
>            writeln('THE CHOICE ENTERED WAS NOT A VALID CHOICE');
>            readln;
>         end;

This calls for  case userchoice of ...

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Re:data segment too large?


In article <yjlAE7LB8I$4E...@merlyn.demon.co.uk>,
Dr John Stockton  <j...@merlyn.demon.co.uk> wrote:

Quote

>In TP7, BP7, &c., continue is already defined; it is unwise to change
>it.  Use, perhaps, "proceed".

>>   until continue = true;

>until continue;  It's a boolean, an enumerated type of values (false,
>true), and until looks for true.

'Until continue' sounds strange. I'd change the name of the
variable as 'valid' or something like that.

Osmo

Re:data segment too large?


JRS:  In article <8dibf4$nu...@kruuna.Helsinki.FI> of Tue, 18 Apr 2000
22:01:56 seen in news:comp.lang.pascal.borland, Osmo Ronkanen

Quote
<ronka...@cc.helsinki.fi> wrote:
>In article <yjlAE7LB8I$4E...@merlyn.demon.co.uk>,
>Dr John Stockton  <j...@merlyn.demon.co.uk> wrote:

>>In TP7, BP7, &c., continue is already defined; it is unwise to change
>>it.  Use, perhaps, "proceed".

>>>   until continue = true;

>>until continue;  It's a boolean, an enumerated type of values (false,
>>true), and until looks for true.

>'Until continue' sounds strange. I'd change the name of the
>variable as 'valid' or something like that.

As I had already said in the first sentence you quote.

PKUATBT.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Re:data segment too large?


On Mon 17 Apr 2000 04:24:46p,  In article <8dfs5s$be...@gxsn.com>,

Quote
cdhennes...@freenetname.co.uk (Craig Hennessey) wrote:
>hi
>when compiling my program (see below) i get a strange error that i have
>never encountered before. this is probably because i have never really
>written any substancial sized programs, but i wouldnt call the program
>below large!
>the error is:

>C:\TP>tpc filecrea
>Turbo Pascal Version 5.5  Copyright (c) 1983,89 Borland International
>FILECREA.PAS(125): Error 49: Data segment too large.

This will answer your question:

http://www.brain.uni-freiburg.de/~klaus/pascal/borland64k.html

Other Threads