[comp.sys.ibm.pc] Environment Size

Usenet_area_"Cs.I.Pc"@watmath.waterloo.edu (01/07/88)

From Usenet: gargoyle!ihnp4!ihlpa!vkar
From: vkar@ihlpa.ATT.COM (Thayalan)
Newsgroups: comp.sys.ibm.pc
Subject: Environment Size
Message-ID: <6770@ihlpa.ATT.COM>
Date: 7 Jan 88 22:32:03 GMT
Organization: AT&T Bell Laboratories - Naperville, Illinois
Lines: 52
Xref: watmath comp.sys.ibm.pc:10366


<<Maybe I'm being dense, but how does one determine the size of the
<<environmment space (ie, how much room there is for environment
<<variables) from within a program?  I can read the environment just
<<fine, I just don't know how much free space there is.
<<
<<(Assuming I ever get this answered, is anyone interested in a Turbo
<<Pascal unit to handle the environment space?)
<<
<<Kenneth Herron


Yes you can find out how much memory DOS has allocated for the environment.
There are two ways to determine this. The cleanest way is to go through
the whole environment, starting from the beginning, byte by byte until
you find two consecutive zero bytes. This way you can determine the 
number of bytes in the environment block, but remember that the memory
is allocated in terms of paragraphs (16bytes). So if you found that the
environment size was 28 bytes long then the environment block is 32 bytes
(ie. 2 paragraphs). BTW, the location of the environment can determined
by looking at the PSP ( program segment prefix ) at location 2cH: this
contains the starting segment address of the environment. 

The second approach is to look at the memory one paragraph before (below)
the environment block. This is the memory control block for the environment
block. The memory control block is created by the operating system, for
every block of memory allocated by it. And the memory control block
contains the size of the environment block. You might not want to use
this approach since this is not officially documented by MS. If you
want more information about this you can read about it in Advanced MS-DOS
by Ray Duncan (page 179).

An important point to note is that DOS will allocate only the minimum
amount of memory neccessary to hold the environment when you execute a
program. In other words, you may specify that you need 1k byte for
the environment of command.com -- you specify this in config.sys file
in the SHELL= line. Then when you invoke another program from command.com
the operating system will create an environment block for this program.
and this block will not necessarily be 1k byte long. It will only be as
big as the actual information in the  environment ( unused portions
will not be passed along). This implies that if a program needs to
modify the environment then it has to allocate memory and copy
the environment received from the parent and then modify this
area. High level-languages have library routines to do this 
 ( C compilers have the "putenv" function to do this for you).
If you program in assembly language then you'll have to create a
an assembly language procedure to do this.
The PC Magazine ( Jan 26,1988 issue) has a good article by
Ray Duncan on this issue.

K. Thayalan
ihlpa!vkar

--- via UGate v1.6
 * Origin: watmath (221/163)

vkar@ihlpa.ATT.COM (Thayalan) (01/08/88)

<<Maybe I'm being dense, but how does one determine the size of the
<<environmment space (ie, how much room there is for environment
<<variables) from within a program?  I can read the environment just
<<fine, I just don't know how much free space there is.
<<
<<(Assuming I ever get this answered, is anyone interested in a Turbo
<<Pascal unit to handle the environment space?)
<<
<<Kenneth Herron


Yes you can find out how much memory DOS has allocated for the environment.
There are two ways to determine this. The cleanest way is to go through
the whole environment, starting from the beginning, byte by byte until
you find two consecutive zero bytes. This way you can determine the 
number of bytes in the environment block, but remember that the memory
is allocated in terms of paragraphs (16bytes). So if you found that the
environment size was 28 bytes long then the environment block is 32 bytes
(ie. 2 paragraphs). BTW, the location of the environment can determined
by looking at the PSP ( program segment prefix ) at location 2cH: this
contains the starting segment address of the environment. 

The second approach is to look at the memory one paragraph before (below)
the environment block. This is the memory control block for the environment
block. The memory control block is created by the operating system, for
every block of memory allocated by it. And the memory control block
contains the size of the environment block. You might not want to use
this approach since this is not officially documented by MS. If you
want more information about this you can read about it in Advanced MS-DOS
by Ray Duncan (page 179).

An important point to note is that DOS will allocate only the minimum
amount of memory neccessary to hold the environment when you execute a
program. In other words, you may specify that you need 1k byte for
the environment of command.com -- you specify this in config.sys file
in the SHELL= line. Then when you invoke another program from command.com
the operating system will create an environment block for this program.
and this block will not necessarily be 1k byte long. It will only be as
big as the actual information in the  environment ( unused portions
will not be passed along). This implies that if a program needs to
modify the environment then it has to allocate memory and copy
the environment received from the parent and then modify this
area. High level-languages have library routines to do this 
 ( C compilers have the "putenv" function to do this for you).
If you program in assembly language then you'll have to create a
an assembly language procedure to do this.
The PC Magazine ( Jan 26,1988 issue) has a good article by
Ray Duncan on this issue.

K. Thayalan
ihlpa!vkar

emb978@leah.Albany.Edu ( Eric M. Boehm) (01/09/88)

I forgot to mention that the same switches (/e: and /p) can also be applied
to child processes (secondary, tertiary, etc. command.com's) that you
invoke. According to the manual, environment size can be up to 32768 bytes
although I have not personally verified this and have had a contradictory
report. In any event, typing

command /e:1000 would reserve 1000 bytes of environment space for the child
process. One word of warning, if you use the /p switch, the system will go
through bootup procedure (read config.sys and command.com) and you will not
be able to get back to the original command.com (since there is now a new
processor to process the exit command).

In relation to the original question (that I did misunderstand), I have a
program that will tell you how much environment space is currently in use
but I don't think that will really help. If you want it, just e-mail me a
request.

smvorkoetter@watmum.waterloo.edu (Stefan M. Vorkoetter) (04/13/89)

Hi.

	I realize that this has been posted before, but I cannot find
any reference to it.  I need to expand the size of the environment
under true blue PCDOS 3.3.  The manual tells me that I can use the
/E:xxxx parameter to the COMMAND command to run a subshell with a
larger environment, but how can I change the enviroment size of the
current command processor.  If someone can point me to a program to
do this, or even the DOS calls needed to do this (if that is how it
is done), I would really appreciate it.  Again, sorry if you've
seen this question (and the answer) before.

Thanks in advance.
Stefan Vorkoetter
smvorkoetter@watmum.waterloo.edu

PS. I would really like something that I can put in my AUTOEXEC.BAT
to change it automatically, since the problem that I am running into
is lack of environment space when setting some variables there.

jmv@sppy00.UUCP (Jim Vickroy) (04/13/89)

In article <9195@watcgl.waterloo.edu> smvorkoetter@watmum.waterloo.edu (Stefan M. Vorkoetter) writes:
=>
=>Hi.
=>
=>	I realize that this has been posted before, but I cannot find
=>any reference to it.  I need to expand the size of the environment
=>under true blue PCDOS 3.3.  The manual tells me that I can use the
=>/E:xxxx parameter to the COMMAND command to run a subshell with a
=>larger environment, but how can I change the enviroment size of the
=>current command processor.  If someone can point me to a program to
=>do this, or even the DOS calls needed to do this (if that is how it
=>is done), I would really appreciate it.  Again, sorry if you've
=>seen this question (and the answer) before.
=>

The SHELL command allows you to use an alternate command processor. 
Additionally you can instruct DOS to permanently use this alternate
command processor. Try this:

	SHELL=C:\COMMAND.COM /E:<environment size> /P

What this does is permanently replaces COMMAND.COM with itself, but with a
larger environment. 

jim
--
==============================================================================
:::: ::: ::  ::   :    :   Jim Vickroy
|OC| ||| ||  ||   |    |   Technical Services Department
|LC| ||| ||  ||   |    |   Online Computer Library Center, Inc.
:::: ::: ::  ::   :    :   Dublin, Ohio
------------------------------------------------------------------------------
UUCP:    {att|pyramid|killer}!osu-cis!sppy00!jmv  
domain:	 jmv@sppy00.uucp
USSNAIL: 6565 Frantz Rd., Dublin, Ohio 43017-0702
------------------------------------------------------------------------------
"Hey, wow man ... pooby shooby"                                            -cm
==============================================================================

asickels@bonnie.ics.uci.edu (Alan Sickels) (04/14/89)

I don't have my manual handy, but try putting this in your CONFIG.SYS
file:

   SHELL = C:\COMMAND.COM /E:xxxx /P

Where 'xxxx' is the environment size and /P is neededd to make the
shell permanent.  BTW this info sould be documented (read it's in the
manual if you have it).

Alan Sickels
Standard signature implied.
Bus error (Passengers dumped)

fs-info@sbsvax.UUCP (Fachschaft Mathe/Info) (04/14/89)

In article <11966@paris.ics.uci.edu>, asickels@bonnie.ics.uci.edu (Alan Sickels) writes:
> [...]
>    SHELL = C:\COMMAND.COM /E:xxxx /P
> [...]
> BTW this info sould be documented (read it's in the
> manual if you have it).
> Alan Sickels
Well, there are manuals and manuals :-)
Ignoring this one (works fine, but the original question was how to change
the environment size of the currently running COMMAND.COM), I got a small
idea. Can't  prove it but i'll tell you :

The Environment is accessed (as far as I know) through a pointer in a
program's PSP. Now assume that the current process, called by COMMAND.COM,
may get it's fathers PSP (think this my be a DOS call). Then it could
determine the old size of the parent's environment, allocate a new environ-
met through DOS, copy the parent's to this new (and bigger) one, setting
the pointers and sizes of the prents PSP according to the new Block
and, this comes to my mind now, changing the OWNER of the newly allocated
environment to it's parent (else, the block will be deallocated when the
size-changer finishes ) (this mut be done by hangling (is this correct
english?) through DOS's memory-chain.
The process MUST do all this heavy stuff with it's parents PSP because the
own environment is a COPY of the parent's at another memory location.
BTW, as far as I know theonly support from MS-DOS U can get are the few
calls mentioned above.
Hope this was helpful, I unfortunately have no time this decade to try it
on my own, but if you get it fixed, please send me the sources.

Greetings from Germany
  Brian o'Fish

/*
 * Brian o'Fish
 * c/o Patrick Schaaf
 * Alter Stadtweg 69
 * D-6602 Dudweiler/Saar
 * GERMANY
 *
 * X.400: fs-info@sbsvax.informatik.uni-saarland.dbp.de
 * Brian o'Fish is an unregistered trademark of my brain. Use him at your
 * own risk.
 */