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
Dyn. Array (Read 434 times)
Dyn. Array
Aug 19th, 2006, 12:54pm
 
Did anyone use dynamic arrays? I searched for it and found this:

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=print;num=1121804047

.. but is it possible to define my dyn array in the setup() and use the same the draw()?

greatings from dresden(germany),
steffen
Re: Dyn. Array
Reply #1 - Aug 19th, 2006, 1:43pm
 
Use Vector, it's much faster than creating your own dynamic array in terms of processing speed and the code will be a lot cleaner.
Code:

Vector stuff;
void setup(){
stuff = new Vector();
stuff.add(new Integer(65));
stuff.add(new Float(3.6));
println("My dynamic array has "+stuff.size()+" objects in it");
Integer foo = (Integer)stuff.remove(0);
println("I have removed the first object which has a value of "+foo.intValue());
println("My dynamic array now has "+stuff.size()+" objects in it");
}

The only weird thing about them is that you'll have to cast and copy them into a temporary object to use stuff in the Vector, but this doesn't slow things down at all. Plus you can use them to create a stack of objects like a pez dispenser, dropping out the first object and the rest shuffling into place.
Re: Dyn. Array
Reply #2 - Aug 20th, 2006, 12:19pm
 
I thank you so much, because to add elements to a string, can not be a good solution. The Vector class is a very good way to get an "dynamic array".

Thanks st33d!

-steffen
Re: Dyn. Array
Reply #3 - Aug 21st, 2006, 6:27pm
 
this might be the wrong place but still a good change to advocate java5 once again. the code would magically tranform into this:

Code:
Vector<Float> stuff;

void setup() {
stuff = new Vector<Float> ();
stuff.add(65.0f);
stuff.add(3.6f);
println("My dynamic array has " + stuff.size() + " objects in it");
float foo = stuff.remove(0);
println("I have removed the first object which has a value of " + foo);
println("My dynamic array now has " + stuff.size() + " objects in it");
}


even nicer, eh?
Page Index Toggle Pages: 1