Re: Object for variable array of fixed structures
Re: Object for variable array of fixed structures
- Subject: Re: Object for variable array of fixed structures
- From: Rush Manbert <email@hidden>
- Date: Mon, 12 Jun 2006 14:38:22 -0700
Steve Sheets wrote:
Just another design question...
Are there any examples of good technique to implement variable size
arrays of fixed structures?
For example, I want to create an array of NSRect inside my code.
Obviously, I could make the data structure be a fixed length array, and
not worry about objects. While this array may be small, but
occasionally it might be as large as a thousand items in the array. I
do not want to always allocated fixed size array all the time.
My solution to handle this involves creating a new category of methods
for NSMutableData (named MyMutableArrayRect), which has calls to size
the array (based on length of NSRect structure), retrieve items in the
array and set items in the array. The new calls look like something like:
- (void) arrayRectSetSize:(int)p_number_item;
- (NSRect) arrayRectGetItem:(int)p_position;
- (void) arrayRectSetItem:(int)p_position
withRect:(NSRect)p_rect;
Originally the new calls were part of a subclass, but I found using a
Category gave me all I needed, while only working with NSMutableData.
Is this the correct approach? I am about to expand this idea to a
couple other large fixed size structure, but using the same basic ideas.
Am I missing something and there is a better approach?
Hi Steve,
Perhaps a stupid answer, but can't you just use NSMutableArray to store
your objects? You need to subclass it if you want to limit what types it
will store, but it sounds like what you're looking for.
- Rush
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden