Re: FIFOs.
Re: FIFOs.
- Subject: Re: FIFOs.
- From: "Clark S. Cox III" <email@hidden>
- Date: Thu, 13 Sep 2001 12:58:06 -0400
On Tuesday, September 11, 2001, at 03:23 , Peter Ammon wrote:
On Tuesday, September 11, 2001, at 12:14 AM, jgo wrote:
From: Ondra Cada <email@hidden>
To: "John C. Randolph" <email@hidden>
Date: Mon, 2001-08-20 16:00:39 +0200
John C. Randolph (JCR) wrote at Mon, 2001-08-20 06:45:10 -0700:
I want a FIFO implemented as a proper thread-safe ring buffer that
will
grow as necessary to prevent overflow, and avoid needless shuffling of
memory as your example will do. I want this FIFO to be writeable by
one
thread while being read by another.
The "memory shuffling" is a roaring nonsense.
Object "clutter" is roaring nonsense.
There just might be one application from 10000 which *MIGHT*
have such demands that NSMutableArray-based FIFO would be
unuseable there, but even that I doubt.
Ah, there you go, again, violating encapsulation by having the
framework/class using developer concerned with the implementation.
The problem with cobbling NSMutableArray is merely that
it is NOT a queue/FIFO, it is not a stack/LIFO; it's an array.
I seem to remember a discussion about this before, where it was revealed
that NSArrays are actually implemented as circular buffers. The memory
shuffling might be less than you think.
You can always download Darwin and check out the implementation of
CFArray.
The point is, one should not be relying on the internal implementation
of any of the Cocoa classes. The whole point of using an object-orientated
language/framework is encapsulation. To be honest, I really don't want to
know how NSArray/CFArray are implemented. This encapsulation gives Apple
the freedom to change the internal implementation without affecting
developers' (well-written) code. If you start to rely on anything that is
not presented by the public API, your code will break when the class'
internals are changed.
If you want a queue/FIFO, then write a queue/FIFO class, if you want a
stack/LIFO, then write a stack/LIFO class, if you want a mutable array
class, then use NSMutableArray.
--
Clark S. Cox, III
email@hidden
http://www.whereismyhead.com/clark/
References: | |
| >Re: FIFOs. (From: Peter Ammon <email@hidden>) |