1MB isn't a whole lot in a modern machine - unless of course you have LOTS of your 1MB variables.
My real question, however, is why you can't just destroy foo and use some other variable when you need a smaller one? That seems like the obvious solution - simpler, indeed, than messing about reserving less memory in foo.
Well, I suppose that's the question. How do I destroy foo? It's a class member and that class needs to stick around & foo *may* need to be filled again with new data? Outside of making foo point to a dynamically allocated string (i.e. string* foo = new string) just so I can delete foo; is there some other way to destroy foo?
Originally Posted by Bjarne Stroustrup (2000-10-14)
I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.