First off I'm sorry I'm so damn thick, but I cant really figure this out.
Ok, I'm at a standstill. I'm using some code to detect objects in a file, I have no way of knowing how many objects of a certain type are in it. But for every object of a certain type, I must allocate a block of memory.
So, I turned to the new statement:
The problem with this (correct me if I'm mistaken) Is that I'm now allocating my pointer new blocks of memory every time I find a new object, rather than incrementing the previous block? So if I have C, I actualy have C, OldBlock right? Then incrementing it again, C, OldBlock, OldBlock. After awhile I'm going to end up with alot of unused memory, so I wanted to delete them.Code:MyClass *C = new MyClass[x+1];
My problem is, I still need the old memory. I cant just go and delete it like that, It contains data I need. So I'm at a conundrum... How do I allocate memory safely, but not end up leaving behind unused chunks? And without using huge ammounts of memory aswell.Code:delete C; MyClass *C = new MyClass[x+1];