Thank you very much. This is a helpful piece of code.

One more problem. When I want to delete the memory, some of them may have already been deallocated, so when I try to free them I get an unhandled exception.

I tried to do something like:

for (int i=0; i<oVector.size(); i++)
{
try
{
free(oVector.at(i);
}
catch(...)
{
continue;
}

} // end for


It doesn't work. I still get unhandled exception errors. Any ideas?