In my current sketch I'm using an array of balls, i need to be able to send the ball ID over OSC, i also need to be able to add and delete balls. Obviously i can add whilst using an array but I'm unsure as to whether or not i need to completely change all of the array stuff in my sketch and replace it with array list functions. Can i use an array list to manage my array?
Basically shall i swap my array for an array list or shall i house and manage my array within an array list?
I like ArrayLists and use them all the time - switched much of my stuff over from an Array and didn't notice any performance loss. If you're going to add a big bulk, you can use the ensureCapacity() function to maximize load performance. From what I understand, they behave very similarly under the hood.
I've pretty much finished the rest of my code, but have realised that i need to be able to remove elements from the array I'm using, so if i changed to array list it shouldn't mess with the rest of my sketch. i.e. would i have to change this:
It is a bit of overkill to use ArrayList for everything. If you know in advance the size and if it is fixed, just use arrays, they will use less memory. Array lists of primitives (int, float, etc.) also have a performance penalty. And the syntax is a bit less friendly.
Otherwise, indeed, an array list is actually just an oversized array, which is grown (and reference to data is copied) when the capacity is reached, so performance isn't bad.
Sorry for chucking a massive bit of code up to answer a bit of a silly question.
Im pretty sure this is my last hurdle before I'm done, so happy days, hopefully its something simple, I've had a good ol go at it but I'm terrible with arrays and arraylists, especially when it comes to naming and declaring. Any help would be hugely appreciated