home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / atari / st / tech / 6514 < prev    next >
Encoding:
Text File  |  1993-01-06  |  2.6 KB  |  52 lines

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