You can do either. There's NSMutableArray for dynamically resizable lists, or you can roll your own. Cocoa's memory management system uses a retain/release architecture: Each object has a reference count, which starts at 1 when the object is allocated, is incremented by retain, and is decremented by release. When it drops to 0, the memory is freed. For the parts of your code that don't directly use Cocoa, you can also do things the good old-fashioned C way with malloc/realloc/free and raw pointers.

Quote:You can do either. There's NSMutableArray for dynamically resizable lists, or you can roll your own. Cocoa's memory management system uses a retain/release architecture: Each object has a reference count, which starts at 1 when the object is allocated, is incremented by retain, and is decremented by release. When it drops to 0, the memory is freed

It's obvious that I'm just starting CO227 (the advanced C++ class focusing on pointers, OO programming, and the.. uh, advanced stuff ) because I have no idea how to work all the dynamic memory things being mentioned. I have some small idea of what malloc does, but beyond that, it looks a whole lot like jibberish to me at the current time.

Quicky on dynamic memory: (main benefit of having an object on the heap (or dynamic memory) is that it outlives the function you create it in)
C:
The function malloc takes the number of bytes you want to allocate to the heap and returns a pointer to that memory. It returns a void pointer, so you will need to cast that to the particular type you need.
If you want to have an struct myObject (typedefed as myObject) on the heap, you have a myObject pointer (myObject *) and you have to call malloc passing in sizeof(myObject) as the parameter. The call would look like this.
myObject *object = (myObject *)malloc(sizeof(myObject));

If you want to have an array of myObject objects, you just multiply the size. Lets say you want an array of 5 of them:
myObject *objects = (myObject *)malloc(sizeof(myObject)*5);
You can then access each of the five objects as you would a normal array (as in from objects[0] to objects[4])

Objects created on the heap must also be destroyed by you, so when you're done, you must call free(object); (same applies for both)

C++:
Instead of calling malloc and free in C++, you use new and delete (though you can still use malloc and free if you want). Basically, instead of having a pointer then calling malloc with a size, you call new then a type. For example, with the same myObject:
myObject *object = new myObject;

then you call delete with it to destroy it when you're done.
delete myObject;

If your object has a constructor that takes parameters, you just call that constructor with the object.
myObject *object = new myObject(parameters);

With an array, you just add brackets with the number of items.
myObject = new myObject[5];

just remember that you also need a bracket after delete
delete[] myObject;

And there you have it! Dynamic memory. (not as hard as you thought, huh? )

So if I have a particle system and I want to have a nice dynamic memory set up going for storing the particles (each being two vectors and a float wrapped up into a nice class), how would I code that into my class?

Here's my guess but I just learned this all from reading that and a few past experiences (that almost never went as planned):

No, that would likely cause a crash. You have to copy it particle by particle. First of all, you will need to have a copy method that will copy all the data from one particle to another. Let's call this copyData. You will also need to store the size of the old array (when you first create it). Let's call it particleSize. You will need to do something like this:

What exactly would go into the CopyData() function that you have in that code? Remember that I'm just learning all this memory management stuff (and it's hard).

Plus you were right about it crashing . I tried it on my own (just to see) and it didn't work too well. This is my entire .cpp file for the class (if you have time, let me know if anything else is going to go wrong so when I get home from work I can fix it):