2D array ?
Nov 28, 2012 at 10:49am
2D array ?
Inside all C Max objects’ source files I have opened I see no use of ANSI C arrays. Everyone seems to use atoms instead. However, which datatype/structure should one use for 2D arrays ?
Any example would be highly appreciated.
Thank you in advance.
Nov 28, 2012 at 12:09pm
Have you opened the examples provided with the SDK or third-party sources ?
In the past, i avoided to use t_atoms and implemented my own library to replace the structures from the SDK (as an exercise for studies) ; It seems that Ádám Siska use C++ STL ; and that is what i’m currently learning (with Boost moreover). I’m sure a lot of various libraries are used by developers. But as t_atom is the main structure used by max objects (for messages, persistence…) you need to use it, and it is sometimes more efficient to use it only.
Most of times 2D arrays are just implemented with 1D arrays and offsets. For example a (3 x 4) array is just an array ; and to get value (x, y) you can do something like that : val = array[(y * 4) + x].
There is various ways to emulate two indexes, but i don’t think it worth the cost.
In case most of the cells of the array are empty ; you can use an hashtab with the index as key ; it can save a lot of memory and is pretty efficient.
Nov 28, 2012 at 1:20pm
Merci Nicolas. Actually yes I have opened the SDK and third-party sources but maybe I expected the arrays in the wrong place. I thought they’d be in the typedef struct definitions and I couldn’t find any in there. Nevertheless I expected to encounter more of them globally. I don’t get where to use regular arrays and where to use atomarrays. At first I thought atomarrays were specifically for symbols but it seems to be used for numbers too.
It’s hard to be a beginner in C and a beginner in Max external programming simultaneously. Still a long way to go !
Nov 28, 2012 at 3:26pm
I started to learn programming with MaxMSP so i have an idea of how long the way is !
Stackoverflow.com and Wikipedia are good starting points for general questions.
Do not hesitate to go through the SDK sources to see under the hood. For example what is a t_atom structure in “ext_mess.h” line 242 ;-)
Nov 28, 2012 at 4:10pm
“At first I thought atomarrays were specifically for symbols but it seems to be used for numbers too.”
You must be logged in to reply to this topic.