From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c233446a6027f1ed X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-16 22:38:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!news.demon.co.uk!demon!pogner.demon.co.uk!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: access / freeing memory Date: 17 Jul 2002 06:22:07 +0100 Organization: Pushface Sender: simon@smaug Message-ID: References: <%WHY8.1173$tt5.52024504@newssvr13.news.prodigy.com> <3D343EF9.3051A6C2@san.rr.com> NNTP-Posting-Host: pogner.demon.co.uk X-NNTP-Posting-Host: pogner.demon.co.uk:62.49.19.209 X-Trace: news.demon.co.uk 1026884267 nnrp-01:7758 NO-IDENT pogner.demon.co.uk:62.49.19.209 X-Complaints-To: abuse@demon.net User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Xref: archiver1.google.com comp.lang.ada:27178 Date: 2002-07-17T06:22:07+01:00 List-Id: Jan Prazak writes: > Now let me resume the memory allocation. When a program starts, the > OS allocates a memory block (say 100 kb) for it, then the program > starts to generate some sort of stack with pointers, and breaks the > 100 kb limit, so the OS gives the program more memory, for instance > 100 kb more. Then the program doesn't destroy the stack, but it > could say "head := null;" or something, or resize the stack without > destroying nodes etc. Then the program ends, and the OS frees all > the memory (200 kb), maybe it goes through every byte and makes sure > that it's not somewhere "marked" as used (I don't know how memory > allocation works in detail.). Was this a good explanation, or am I > still wrong in some points? On a typical host OS like Windows or GNU/Linux, the OS makes memory available to a process (execution of a program) on request, in chunks (usually called "pages", size depends on CPU and OS; perhaps 2kB). When the process dies, the OS just deletes all the allocated pages. No need to chase pointers; just delete the pages[1]. On the other hand, your typical real-time OS (like say VxWorks) doesn't manage memory in this way. If your program never stops (perhaps it's an engine control system), you don't have to worry about what the OS would do if it did (though you still have to worry, a lot, about memory leaks). But if you are running unit tests and you forget to return memory at the end of your program, it's gone (until you reboot and wipe the slate clean, which might not be such a bad idea at that!). [1] There is a lot of detail omitted here!