C
Chris Portka
I need to be able to allocate large numbers of elements at a time but
then delete them one at a time. I have settled on the design of using
new[] to allocate many items at once, but am unsure what is legal/
illegal about deallocation. Here's an example of what I would like to
do:
int *x = new int[1000];
....
delete x;
....
delete x+1;
....
delete x+2;
....
....
delete x+999;
Can I do this? Or do I have to delete the entire allocated array in
one chunk using delete[]? This example is not entirely accurate as I
would like the ordering of deletes to be more or less arbitrary. Any
help is greatly appreciated. Thanks,
-Chris
PS - If you want to know why I want this done - it's because I want to
save time allocating many objects instead of just one at a time and
I'll be passing pointers to these objects to many different functions
and places which will use them for awhile and then want to be able to
delete them.
then delete them one at a time. I have settled on the design of using
new[] to allocate many items at once, but am unsure what is legal/
illegal about deallocation. Here's an example of what I would like to
do:
int *x = new int[1000];
....
delete x;
....
delete x+1;
....
delete x+2;
....
....
delete x+999;
Can I do this? Or do I have to delete the entire allocated array in
one chunk using delete[]? This example is not entirely accurate as I
would like the ordering of deletes to be more or less arbitrary. Any
help is greatly appreciated. Thanks,
-Chris
PS - If you want to know why I want this done - it's because I want to
save time allocating many objects instead of just one at a time and
I'll be passing pointers to these objects to many different functions
and places which will use them for awhile and then want to be able to
delete them.