Too many global vars... HELP! 
Author Message
 Too many global vars... HELP!

Can anyone tell me how to increase my stack size for a dos program
written in borland c++ 4.51.

It seems that I ran out of stack space.  I received the error message

TOO MUCH GLOBAL DATA DEFINED IN <FILE.CPP>

The help function said to allocate them on the heap with malloc()
or to declare them _far16 <-- which is for windows progs only.

Anyway, I'm stuck...



Fri, 16 Apr 1999 03:00:00 GMT  
 Too many global vars... HELP!

Quote:


> > Can anyone tell me how to increase my stack size for a dos program
> > written in borland c++ 4.51.

> > It seems that I ran out of stack space.  I received the error message

> > TOO MUCH GLOBAL DATA DEFINED IN <FILE.CPP>

> I don't know about bc++ 4.51, but if it complains that it has not enough
> space for allocating *global* data, I don't see why expanding the *stack*
> should help.

Hope I remember this right (It's quite a long time when I coded 16 bit
;-), so
sorry if this is not correct:

I think it will help, because all of the global variables goes into
stack segment
with tiny/small/compact/medium memorymodel (Assume: Stack Segment = Data
Segment)
If you use large/huge memorymodel then SS != DS.
So try to switch (with medium memorymodel) SS == DS -> SS != DS and then
both
will have 64kb memory area... ...was it automatic in BC++ ???

Anyway. Is'nt there any other way to code your program -> running out of
space for global data sounds like 'a bad programming style' to me.

--------------------------------------------------------------
Jukka Palander, Software Engineering, Fujitsu ICL Data Softia
Addr: Valimotie 16, 00380 Helsinki, Finland
Po box: PL 458, 00101 Helsinki, Finland
Tel: +358-9-5671, Private: ++567 3689, Fax: ++567 3663

X.400: C=FI A=ELISA P=ICL OU1=FIN1001 O=ICL S=Palander G=Jukka
--------------------------------------------------------------



Sun, 18 Apr 1999 03:00:00 GMT  
 Too many global vars... HELP!

Quote:

> Can anyone tell me how to increase my stack size for a dos program
> written in borland c++ 4.51.

> It seems that I ran out of stack space.  I received the error message

> TOO MUCH GLOBAL DATA DEFINED IN <FILE.CPP>

I don't know about bc++ 4.51, but if it complains that it has not enough
space for allocating *global* data, I don't see why expanding the *stack*
should help.

You seem to be compiling for DOS, not for Windows. What memory model
are you using? Did you consider allocating part of your globals on the
heap?
--

Ronald Otto Valentin Fischer


http://ourworld.compuserve.com/homepages/ronald_fischer



Sun, 18 Apr 1999 03:00:00 GMT  
 Too many global vars... HELP!

: Can anyone tell me how to increase my stack size for a dos program
: written in borland c++ 4.51.
: It seems that I ran out of stack space.  I received the error message
:
: TOO MUCH GLOBAL DATA DEFINED IN <FILE.CPP>
:
: The help function said to allocate them on the heap with malloc()
: or to declare them _far16 <-- which is for windows progs only.

There is a compiler switch -Ff and I think this is what they are referring
to. This automaticlly makes all variables as far reference. You could also
try reducing the size of you stackor if you have lots of string constants
try:
   -d  merge duplicate strings
   -dc constant strings to code segment


Author of: Hardware Digital Logic Analyers for Windows
           Zeus for Windows, Win32 (Brief, WordStar, Emacs) Text Editor
"The C/C++, Java, Pacal, fortran and integrated development environment"
Home Page: http://ourworld.compuserve.com/homepages/jussi/



Sun, 18 Apr 1999 03:00:00 GMT  
 Too many global vars... HELP!

Quote:



> > > Can anyone tell me how to increase my stack size for a dos program
> > > written in borland c++ 4.51.

> > > It seems that I ran out of stack space.  I received the error message

> > > TOO MUCH GLOBAL DATA DEFINED IN <FILE.CPP>

> > I don't know about bc++ 4.51, but if it complains that it has not enough
> > space for allocating *global* data, I don't see why expanding the *stack*
> > should help.

> Hope I remember this right (It's quite a long time when I coded 16 bit
> ;-), so
> sorry if this is not correct:

> I think it will help, because all of the global variables goes into
> stack segment
> with tiny/small/compact/medium memorymodel (Assume: Stack Segment = Data
> Segment)
> If you use large/huge memorymodel then SS != DS.
> So try to switch (with medium memorymodel) SS == DS -> SS != DS and then
> both
> will have 64kb memory area... ...was it automatic in BC++ ???

> Anyway. Is'nt there any other way to code your program -> running out of
> space for global data sounds like 'a bad programming style' to me.

I agree whole heartedly  I don't claim to be super C++ Master supreme
but in the thousands and thousands of lines that I've written I've never
encountered a problem with too many global variables.  There has to be a
way of cutting down on them and in the end they will probabily bite you
in the ass anyway...
 But using a larger memory model should clear up the problem SS != DS
will give you an extra 64k of data space and your stack size has nothing
to do with globals because they are statically bound at compile time,,
or is it link time?  I forget with CPP...

- Show quoted text -

Quote:
> --------------------------------------------------------------
> Jukka Palander, Software Engineering, Fujitsu ICL Data Softia
> Addr: Valimotie 16, 00380 Helsinki, Finland
> Po box: PL 458, 00101 Helsinki, Finland
> Tel: +358-9-5671, Private: ++567 3689, Fax: ++567 3663

> X.400: C=FI A=ELISA P=ICL OU1=FIN1001 O=ICL S=Palander G=Jukka
> --------------------------------------------------------------



Thu, 22 Apr 1999 03:00:00 GMT  
 Too many global vars... HELP!



Quote:



> > > > Can anyone tell me how to increase my stack size for a dos program
> > > > written in borland c++ 4.51.

> > > > It seems that I ran out of stack space.  I received the error
message

> > > > TOO MUCH GLOBAL DATA DEFINED IN <FILE.CPP>

> > > I don't know about bc++ 4.51, but if it complains that it has not
enough
> > > space for allocating *global* data, I don't see why expanding the
*stack*
> > > should help.

> > Hope I remember this right (It's quite a long time when I coded 16 bit
> > ;-), so
> > sorry if this is not correct:

> > I think it will help, because all of the global variables goes into
> > stack segment
> > with tiny/small/compact/medium memorymodel (Assume: Stack Segment =
Data
> > Segment)
> > If you use large/huge memorymodel then SS != DS.
> > So try to switch (with medium memorymodel) SS == DS -> SS != DS and
then
> > both
> > will have 64kb memory area... ...was it automatic in BC++ ???

No matter what you set the switch to, or what memory model you use, the
stack and "default" data segment (pointed to by the DS register more of the
time) are always the same in a 16-bit Windows program.  That is, in a
16-bit Windows EXE, SS always equals DS (this major detail is what allows
for that "smart callbacks" option your compiler probably has).  

The SS != DS issues arise only when compiling a DLL, which can be called on
any stack (SS is some client EXE's stack), but still has its own data
segment.  So, when the DLL code executes, SS is not necessarily the same as
DS.  

The SS/DS-related switches most compilers have simply allow for generation
of different code (possibly taking advantage of SS == DS, etc.) when
compiling.

Quote:
> > Anyway. Is'nt there any other way to code your program -> running out
of
> > space for global data sounds like 'a bad programming style' to me.

> I agree whole heartedly  I don't claim to be super C++ Master supreme
> but in the thousands and thousands of lines that I've written I've never
> encountered a problem with too many global variables.  There has to be a
> way of cutting down on them and in the end they will probabily bite you
> in the ass anyway...
>  But using a larger memory model should clear up the problem SS != DS
> will give you an extra 64k of data space and your stack size has nothing
> to do with globals because they are statically bound at compile time,,
> or is it link time?  I forget with CPP...

In a 16-bit Windows program, the stack and global variables (static data)
*are* very much related.  No matter what the memory model, they both exist
in the default data segment, which has a maximum size of 64K.  More stack
means fewer globals.  More globals mean less stack.  The default data
segment also contains the local heap, but that doesn't get used very much
in modern Windows programs so it's mainly a battle between stack and static
data.

In a 32-bit (Win32) Windows program, stack and static data are not related.

More specific discussion on where global variables go in a Windows program
should probably be directed to a more appropriate newsgroup, such as
comp.os.ms-windows.programmer.misc, etc..

Regards,
-------------------------------------------------------------------------
Matt Arnold                   | class Disclaimer {

Boston, MA                    |    Disclaimer() { opinion = L"Mine!"; }
C++, MIDI, Win32/95 developer | private:
e fan                         |    wchar_t* opinion; };
-------------------------------------------------------------------------



Fri, 23 Apr 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. global vars vs: local vars

2. global/static vars inside loops

3. const global vars

4. Global vars versus pointers

5. how to access local and global vars in a function

6. global vs local vars

7. global/static vars inside loops

8. static global vars and functions

9. global Vars

10. Global vs. Local vars and .MAP

11. Accessing vars in global and module scope in ANSI C

12. Accessing vars in global and module scope in ANSI C

 

 
Powered by phpBB® Forum Software