🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.pc
Article #8739

Memory alloc and a shell

#8739
From: Scott Presnell
Date: Thu, 06 Nov 1986 21:01
45 lines
2443 bytes
Fellow netlandians,
I have a situation that I do not understand I'm hoping someone out there
can help...
Language: MS `C' ver 4.0
Goal: Completion shell (crude)
Problem: Memory allocation

Each time I enter the command line to this shell, the program parses it,
decides what executable to call, then asks for another command line. Each
time the loop is executed, calls to malloc are made: at the bottom of the
loop calls to free are made. By watching malloc space with _freect() I can
see that I am getting back everything that I malloc. But, the sbrk(0)
value continues to increase and the _memavl() shows less and less memory
'free' in the segement. Eventually I run out of memory in the segment, but
I never crash. All this time the value returned by _freect(sizeof(char))
returns the same value at the bottom of the loop.

If I try to limit the the allocation space with `exemod /max xx' (or the
similar link switch), Initally the allocated space is smaller, (as viewed
by chkdsk) but gradually the shell takes over more and more of the segment.
When I set the allocation max to the allocation min _memaval() shows zero,
but still sbrk(0) increases. By the way the stackavl is always the same
value at the bottom of the loop.

What is going on here? Could it be that I'm loosing memory space by going
in and out of functions that my main loop calls? Should I declare
values in sub-functions static? I'm just tossing out ideas I'm not very
experienced in memory management.

Any serious comments are welcome. Posting replies is fine, but please also
mail me directly as our News service is still a little behind since the
seismo switch.

Thanks in advance.

-- 
-----------

Scott Presnell  Eidgnoessische Technische Hochschule, Zuerich (ETH-Zentrum)
		Labor Fuer Organische Chemie
		Universitaetsstrasse 16
		CH-8092 Zuerich Switzerland.

uucp:		...seismo!mcvax!cernvax!ethz!srp     (srp@ethz.uucp)
earn/bitnet:	Benner@CZHETH5A
Technical Details
Message-ID: <398@ethz.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!seismo!mcvax!cernvax!ethz!srp

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!seismo!mcvax!cernvax!ethz!srp
From: srp@ethz.UUCP (Scott Presnell)
Newsgroups: net.micro.pc
Subject: Memory alloc and a shell
Message-ID: <398@ethz.UUCP>
Date: Thu, 6-Nov-86 16:01:59 EST
Article-I.D.: ethz.398
Posted: Thu Nov  6 16:01:59 1986
Date-Received: Fri, 7-Nov-86 22:06:44 EST
Organization: Chem. Dept., Swiss Federal Inst. of Tech. (ETH-Zurich)
Lines: 46