We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Array length methods (Read 4593 times)
Array length methods
Jun 11th, 2005, 10:10pm
 
The new array controls are very handy (expand, concat, etc.).

I am aware that these do not work with objects (homemade Classes). It gives me the impression that System.arraycopy() is not employed in these operations. So I imagine there is some other expedient method (I've lost the link to the API source, sorry).

Is there any plan to extend array length handling to objects? With the same or different functions perhaps. Or should we stick to arraycopy and java's vectors?

I ask because I think you guys would have the better experience of what's best in terms of a student's development.
Re: Array length methods
Reply #1 - Jun 13th, 2005, 5:31am
 
I usually do something like this

Code:

thing thingArray[];

void setup()
{
size(100,100);
thingArray=new thing[200];
for(int i=0;i<thingArray.length;i++)
thingArray[i]=new thing();
}
void draw()
{

}
class thing
{
float data;
thing()
{}
thing(thing t)
{
this.data=t.data;
}
}

thing[] append(thing t[],thing newThing)
{
thing temp[]=new thing[t.length+1];
System.arraycopy(t,0,temp,0,t.length);
temp[t.length]=new thing(newThing);
return temp;
}



For every custom class I make. Yeah, it's a bit tedious. Someone smarter might come up with a universal "appendage".
Re: Array length methods
Reply #2 - Jun 13th, 2005, 3:22pm
 
yup, universal versions are coming soon...

see also: http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Suggestions;action=display;num=1114443601;start=0
Re: Array length methods
Reply #3 - Jul 28th, 2005, 5:54pm
 
status of this can now be tracked in the bugs db:
http://dev.processing.org/bugs/show_bug.cgi?id=115
(closing thread, please do any follow-up there)
Page Index Toggle Pages: 1