Actually, with modern operating systems it's rather unlikely you ran out of memory. Before you do that, the machine will swap so heavily, that it becomes more or less unusable - you cannot miss that. Also, when I conducted experiments with Win2k a few years ago, I found that just about every application crashed when my test app allocated as much memory as it could get. (That included the debugger, office applications, the browser, the email app, and even notepad.)
So I would assume you're either trying to allocate an unreasonably large amount or the heap becomes fragmented so badly that it isn't able to serve even reasonable requests.
How about writing your code this way:
// for example
const std::size_t arbitrary_max_size_constant = std::vector<float>::max_size();
// or std::nummeric_traits<std::size_T>.max() / 10;
if (texture!=NULL){
assert(mesh->numSurfacePoints < arbitrary_max_size_constant);
texCoords = new float[mesh->numSurfacePoints*2];
// ...
}
This will alert you in debug modus if your program has a bug, but won't slow down release code. Another possibility would be that you catch the exception and print the memory the program was trying to allocate:
if (texture!=NULL) {
try {
texCoords = new float[mesh->numSurfacePoints*2];
} catch(const std::bad_alloc& x) {
std::cerr << "failed to allocate << mesh->numSurfacePoints*2 << " bytes!\n";
throw;
}
// ...
}
This way you'll also see whether the value is unreasonably big. If it is, you've got a bug, if it isn't, you either run out of memory or the heap is too fragmented to allocate the amount the program needs at this place.