From: brianm@ims.com (Brian McLaughlin)
Subject: Re: memory questions
dnskiesling@telis.org (David Kiesling) writes:
|> I've been using PowerBasic for some time but never really understood
|> exactly how memory is structured. [...]
Memory is a complex subject. Here is some background info,
as it applies to PowerBasic:
Part of an EXE file's header contains instructions to the
operating system about how much memory the program needs.
All compiled Basic programs follow a convention of asking
for far more memory than could ever exist. In that case, the
loader takes all available convenitonal memory and assigns
it to the program.
However much memory is given to the program, it is divided
up in the following major ways:
One segment is set aside as DGROUP. This segment contains
all the static variables and arrays in your program, the
stack, and a fair number of other pieces of data.
One or more segments are set aside for program code. Any
memory that is left over is the far heap. This is where
dynamic arrays and string segments are allocated.
It is important to understand that a memory segment can be
as small as 16 bytes, or as large as 64K, but no larger.
|> It mentions the stack is used by a program for local variables in
|> procedures and functions [...] But where is this "stack"? Is it
|> somewhere in the 640k conventional memory?
The stack is located in the 640K conventional memory. It is in
the DGROUP segment.
|> What about string segments? What's up with
|> those? Is that where all other strings in a program are stored? Do
|> numeric variables go there too?
String segments are dynamically allocated, as they are needed.
The size of a string segment defaults to 32K, but you can adjust
it using the $STRING metacommand. String segments only hold
variable length string data, no numeric data. They are in the
far heap.
|> What about RAM, and files on the hard disk? How are those structured
|> and how is stuff stored in those places?
Under DOS, the hard disk is governed by the FAT system.
That is a whole 'nother complex subject.
RAM is the same as memory, so I'm not sure what you are asking
there.
|> What about static and dynamic variables? How are those stored/used?
Since a static variable is known at compile time, it's actual
value is stored in the EXE file at compile time. At run time,
the value is stored in DGROUP.
Dynamic variables are stored in the far heap. Local
variables are stored on the stack.
|> If I were to dimension a dynamic string array with each variable
|> having a maximum (but not fixed) length of 12 (I'm thinking of 8.3
|> filenames here), how would I be able to tell, before dimensioning the
|> array, what the maximum number of elements is that I could fit into
|> memory? (using PowerBasic 3.5)
I would need to have the documentation of FRE in front of me,
and, sadly, I don't. Variable length strings have some
overhead involved, beyond the length of the string data
itself. So, if you have 1000 bytes of memory available, you
cannot fit 100 strings of 10 bytes each in that amount of memory.
I don't have all the details at hand, though. Sorry.
|> Then, what about into EMS memory?
Does PB35 allow you to put variable length string data in EMS?
--
Brian McLaughlin, Technical Writer |"Thanks to the Internet, misinformation
Integrated Measurement Systems, Inc.| now travels faster than ever before!"
Beaverton, OR, USA | ---- Standard disclaimer applies ----
*** QwkNews (tm) v2.1
* [TN71] Internet Newsgroup: alt.lang.powerbasic
--- GEcho 1.20/Pro
---------------
* Origin: Toast House Remote (1:100/561)
|