srp@ethz.UUCP (Scott Presnell) (11/07/86)
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