home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 22354 < prev    next >
Encoding:
Text File  |  1993-01-28  |  3.4 KB  |  90 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!saimiri.primate.wisc.edu!caen!uwm.edu!spool.mu.edu!darwin.sura.net!newsserver.jvnc.net!gmd.de!Germany.EU.net!mcsun!chsun!bernina!bernina!neeri
  3. From: neeri@iis.ethz.ch (Matthias Neeracher)
  4. Subject: Re: A malloc() built upon sbrk() on a Mac?
  5. In-Reply-To: boortz@sics.se's message of Wed, 27 Jan 1993 10:57:28 GMT
  6. Message-ID: <NEERI.93Jan27192832@iis.ethz.ch>
  7. Sender: news@bernina.ethz.ch (USENET News System)
  8. Organization: Integrated Systems Laboratory, ETH, Zurich
  9. References: <BOORTZ.93Jan27115728@dunlop.sics.se>
  10. Distribution: comp
  11. Date: Wed, 27 Jan 1993 18:28:32 GMT
  12. Lines: 76
  13.  
  14. In article <BOORTZ.93Jan27115728@dunlop.sics.se>, boortz@sics.se (Kent Boortz) writes:
  15. > I have a malloc() replacement that I want to port to Mac.
  16. > It assumes a continuous memory area and a upper bound
  17. > moved by the Unix sbrk() call.
  18.  
  19. > What I came to think of is this:
  20.  
  21. > 1.    Allocate a fixed stack space (this is the normal way
  22. >     on a Mac, isn't it?)
  23.  
  24. Yes.
  25.  
  26. > 2.    Allocate with NewPtr() memory at the lowest address
  27. >     in the application heap. This will be immediately
  28. >     after the stack space.
  29.  
  30. No. This is *opposite* the stack.
  31.  
  32. > 3.    Implement sbrk() with SetPtrSize() on this memory area
  33. >     and let malloc() take memory from this area.
  34.  
  35. Bad idea. This assumes that nobody ever does a NewPtr or allocates too many
  36. handles in your heap after you have started your malloc() (I broke a version of
  37. Lightspeed Pascal which had this assumption a few years ago).
  38.  
  39. > 4.    If SetPtrSize() fails I do a MaxApplZone() and try
  40. >     again.
  41.  
  42. Useless. If there is any way to make SetPtrSize succeed, the Memory Manager
  43. will make it succeed. If you allocate a fixed size stack, you should call
  44. MaxApplZone anyway.
  45.  
  46. > This way my "Unix" memory handling will grow from low application
  47. > heap address to high and normal mac allocation will grow from
  48. > high memory address to low.
  49.  
  50. Unfortunately, "normal" Mac allocation isn't all handles (And handles are not
  51. allocated high to low, but that's besides the point).
  52.  
  53. > My problem is to do (2) because normally I can't tell the mac memory 
  54. > manager where I want to take memory.
  55.  
  56. Actually (2) was the single most workable point in your proposal. Simply
  57. calling NewPtr will ensure a best effort from the Memory Manager to place your
  58. memory as low as possible.
  59.  
  60. >A solution to that could be:
  61.  
  62. >         AllocMem = NewPtr(MaxMem(&any));
  63. >         SetPtrSize(AllocMem,size_wanted);
  64.  
  65. No especially good idea, I'm afraid. In the presence of locked handles, this
  66. might be quite counterproductive.
  67.  
  68. > Any thought about this? Is there other ways of doing what I want?
  69.  
  70. Frankly, I get the impression that you are not very experienced with Macintosh
  71. memory management, which makes me wonder why you think you need that malloc()
  72. replacement in the first place.
  73.  
  74. Maybe you might want to check out Tim Endres' malloc package, which is at
  75. ftp.msen.com, pub/mac/src/icemalloc.hqx. I have no actual experience with it,
  76. but as it was already written for the Mac, it certainly doesn't contain any
  77. sbrks().
  78.  
  79. > Is there any way of doing mmap() on a mac?
  80.  
  81. This probably depends on the model and the System version. It *might* work
  82. under A/UX.
  83.  
  84. Matthias
  85.  
  86. -----
  87. Matthias Neeracher                                   neeri@iis.ethz.ch
  88.  "You must have picked up that copy of Scarlett instead of Inside Mac
  89.   when you tried to find the right call..." -- Keith Rollin
  90.