Re: 2D Arrays
Re: 2D Arrays
- Subject: Re: 2D Arrays
- From: Graham Wheel <email@hidden>
- Date: Sun, 08 Jun 2003 12:08:19 -0700
>
what is your array element?
>
>
floats, void *, id? Is it atomic or struct?
>
>
the answer depends on the element type.
My array elements are pointers to home-grown Complex number objects, and I want to implement some methods to do operations on matrices of complex numbers. My immediate application uses small matrices (<10x10), but I would like to try and write the code so that it scales to larger matrices (say, 100x100) without an unreasonable performance penalty.
>
Well, you can do it with NSArray, of course. Just insert arrays into
>
your array and you can do like
>
>
[[array objectAtIndex:i] objectAtIndex:j] etc
I suppose I could simulate a 2D array without having using to use a nested NSArray objectAtIndex: method to access each element as follows:
[array objectAtIndex:(i*rowsize + j)]
That way I could get the benefits of using NSArray without the penalty of sending two messages to the NSArray objects.
>
2d arrays are just a bunch of usual (1d) arrays in a usual array. i
>
find '2d', '3d'.. arrays a misleading concept and not very helpful.
I think they are useful for modeling 2D or 3D etc real world objects.
>
Do not hesitate to simply create a standard 2D C-style array, and use
>
it to point to NSObjects - that works fine. Otherwise, create "arrays
>
of arrays" using NSArray, as others have suggested.
I'd like to use a Cocoa object so I can take advantage of the built-in functionality, like memory management. If I use C-style arrays, I'll have to use malloc() and free() I suppose to dynamically create and destroy the arrays.
Thanks for all your hints! You've given me lots of food for thought.
Graham
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.