home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.atari.st.tech
- Path: sparky!uunet!spool.mu.edu!wupost!csus.edu!netcom.com!ersmith
- From: ersmith@netcom.com (Eric R. Smith)
- Subject: Re: Malloc (Was: Sending objc_draw to a buffer)
- Message-ID: <1993Jan6.224937.10888@netcom.com>
- Organization: Netcom Online Communications Services (408-241-9760 login: guest)
- References: <2b3de6cf@p15.f202.n281.z2.fidonet> <1993Jan3.035343.15539@netcom.com> <1993Jan4.203951.6091@dcs.warwick.ac.uk>
- Date: Wed, 6 Jan 1993 22:49:37 GMT
- Lines: 41
-
- In article <1993Jan4.203951.6091@dcs.warwick.ac.uk> leo@dcs.warwick.ac.uk (Leo Hendry) writes:
- >In article <1993Jan3.035343.15539@netcom.com> ersmith@netcom.com (Eric R. Smith) writes:
- >>Most libraries' malloc() functions will handle everything automatically,
- >>allocating memory in large chunks (4K or 8K or even 32K) from the OS
- >>and then splitting those chunks up as necessary.
-
- >Do you know of any librarys that will Mfree() blocks once all parts of them
- >have been free()ed though? If none do then we have know choice but to use
- >Malloc() directly in a multi-tasking system or else the user will have to
- >shut down applications and restart them to free "lost" memory.
-
- Yes, some libraries do Mfree() blocks. Most do not. There are advantages
- and disadvantages both ways (the advantage of *not* freeing the memory
- is speed; if your program needs to malloc() again and the block *is*
- freed, then there is an overhead of 2 system calls (Mfree and then another
- Malloc).
-
- It is possible that a program will need to do a very large malloc(), free
- the memory, and then never need that much memory again. In this case
- there could be "lost" memory. I still recommend using your C library
- malloc() function, though, because this kind of situation is relatively
- rare (and easily special-cased around, i.e. you can use Malloc/Mfree
- for specific large blocks of memory that you know you will never need
- again).
-
- Programs that use Malloc and Mfree for general purpose memory management
- (i.e. that have lots of calls like "foo = Malloc(100L)") are already
- slower than they need to be, and will definitely consume far more
- memory than necessary under memory protection/virtual memory versions
- of MultiTOS or TOS.
-
- Finally, the other advantage of malloc() and free() is portability;
- these are standard C functions and so are available in every library
- and on every platform, not just the Atari. (I know, that's often not
- a concern if you're only writing for the Atari ST, but it never hurts
- to make your software easy to port to other machines or operating
- systems.)
-
- Eric Smith ersmith@netcom.com
- Opinions expressed above are my own; Atari has their own opinions, I'm sure.
-
-