home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21033 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.9 KB  |  47 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!data.nas.nasa.gov!taligent!kip-28.taligent.com!user
  3. From: keith@taligent.com (Keith Rollin)
  4. Subject: Re: Why is new(p) so slow in THINK Pascal?
  5. Message-ID: <keith-080193125909@kip-28.taligent.com>
  6. Followup-To: comp.sys.mac.programmer
  7. Sender: usenet@taligent.com (More Bytes Than You Can Read)
  8. Organization: Taligent
  9. References: <4940@svin09.info.win.tue.nl> <C0JIxw.3KG@world.std.com>
  10. Date: Fri, 8 Jan 1993 21:03:22 GMT
  11. Lines: 34
  12.  
  13. In article <C0JIxw.3KG@world.std.com>, siegel@world.std.com (Rich Siegel)
  14. wrote:
  15. > In article <4940@svin09.info.win.tue.nl> wstomv@win.tue.nl writes:
  16. > >In order to compare some sorting procedures for linked lists (implemented
  17. > >in THINK Pascal) I applied them to random lists of varying lengths.
  18. > >It turns out that the procedure new(p), which allocates storage for
  19. > >a dynamic variable pointed to by p, is extremely slow.  Does anyone
  20. > >know why?  New-ing a thousand items takes a noticeable time, new-ing
  21. > >10,000 items takes minutes (on my lowly SE/30).
  22. > New() for pointer variables simply calls NewPtr. With that many small
  23. > blocks, you're overloading the Memory Manager, which has to find space
  24. > low in the heap each time you call New. Under the circumstances, you
  25. > might want to think about an alternative storage strategy.
  26. > Starting with an initial free list of pointer blocks is OK, but you're
  27. > still hammering the Memory Manager - you might want to think about
  28. > allocating a single large chunk and using pieces of it as you need them.
  29.  
  30. MPW Pascal, as well as malloc() in both THINK and MPW C, does this.
  31. Chunking instead of calling NewPtr each time is a *big* win. I did a simple
  32. test:
  33.  
  34. p = NewPtr(50) 10,000 times = 3917 ticks
  35. h = NewHandle(50) 10,000 times = 238 ticks
  36. p = malloc(50) 10,000 times = 26 ticks.
  37.  
  38. ...on my lowly Quadra 900.   :-)
  39.  
  40. -----
  41. Keith Rollin
  42. Phantom Programmer
  43. Taligent, Inc.
  44.