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