|
Ravi Bhavnani wrote: Or
Shouldn't it be AND ?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
All the world's a stage,
And all the men and women merely players.
They have their exits and their entrances;
And one man in his time plays many parts... --William Shakespeare
|
|
|
|
|
No, that would be incorrect grammar.
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: would be incorrect grammar
I actually intended the AND/OR logical operator.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
All the world's a stage,
And all the men and women merely players.
They have their exits and their entrances;
And one man in his time plays many parts... --William Shakespeare
|
|
|
|
|
By default, new throws an exception, so just put a try catch in the main function if you want to handle out of memory.
That is assuming you're doing embedded development.
Doing out of memory checking is fairly pointless for desktop apps, because of virtual memory.
|
|
|
|
|
I always implicitly test for (and handle) out-of-memory conditions, by getting __new_handler to throw a real c++ exception. The question was if I explicitly test for out of memory conditions, so the answer has to be 'no'.
In the few cases when I don't use new (e.g. in the boost pool allocator, or SysAllocString) I check for out-of-memory explicitly, so it never goes unhandled, which I think would have made a better question.
This is in a server app, where the client has been known to make requests so big they exceed the 2gb virtual memory space limit, so it is essential that we handle out-of-memory conditions properly.
|
|
|
|
|
I've worked on machines that nearly ran out of hard drive space thanks to virtual memory. I play it safe and test everything.
|
|
|
|
|
new only fails after it runs out of virtual memory.
|
|
|
|
|
"Doing out of memory checking is fairly pointless for desktop apps, because of virtual memory."
Well, well. There are no 2 systems which are the same. One can't expect an unlimited amount of memory, or an unlimited amount of virtual memory. And there are - many - types of apps where memory availability is a real issue, at least from where I'm standing (image and video processing, large scale, large resolution, large databases, and so on). My rule is always to expect the worst.
|
|
|
|
|
Yeah, now that I think about it I'd say it's worth doing, considering it's only 4 extra lines of code. Having said that those large scale apps you're talking about are pretty rare. You're average run of the mill app will never run out of memory.
|
|
|
|
|
I am programing the 3D graphics applications which operate with large amount of data. So memory limit can be hit pretty fast.
|
|
|
|
|
Computer graphics always hunger for more and faster processors and yet more memory. There is always a higher resolution, a greater color depth, a need for a larger 3D buffer for a more detailed object and a good use for more and more 3D objects. This will never change.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
he he, neat
|
|
|
|
|
The consequences are not the same if you program a game or an securty system as a ABS or ESP !
|
|
|
|
|
No, actually it does not. A crashing game may not be a matter of life and death, but an angry gamer also is a dissatisfied customer.
A user interface should always show exactly, what the user's options are at this moment. Also, it should tell the user why an option is not available at the moment. I simply don't let the user do memory intensive stuff and simply wait for the exception to happen. Predicting trouble and telling the user what he can do about it leaves an entirely different impression.
Then there are sequences of operations which may become very complicated to undo if any serious error occurs somewhere in the middle. Checking the most probable causes of errors in advance, including memory limitations, may help by not letting the error occur in the first place.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
...64K. If the OS can't spare 64K, then my program will be the least of your worries.
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
Commodore 64 lives...!
|
|
|
|
|
Who needs more than 16 bits worth of address space anyway?
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
It seems to me, having a program crash because the system ran out of memory is the most ridiculous thing ever. If there isn't enough memory available to create a new object, the OS shouldn't crash the program--it should simply pause it and give an out of memory warning to the user so they can free some up and then the program would unfreeze when enough is available to continue safely. Yeah there are a few scenarios this would still have problems with (like remoting) but for the most part it would be a lot nicer.
In such a managed world, having your program throw a random exception when there is no more memory is just strange. I remember the first time I got that exception--I was like "are you kidding??".
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
|
Cristian Amarie wrote: You're kidding, right?
What if you were working on something important and didn't have it saved when you run out of memory? Which do you think is the better situation?
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
|
Cristian Amarie wrote: I wouldn't drive a car that stops itself in the middle of highway just because the gas is running low.
My 0.2.
Would you prefer it just blew up when it reached 0?
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
No, that's why we prefer BOSD that tries to prevent disaster when critical error occurs. If system crash cause losing of my _unsaved_ work its my own fault for not saving the documents, but if it trashes my _saved_ files, huh, now that is bad, very bad...
|
|
|
|
|
Mladen Jankovic wrote: If system crash cause losing of my _unsaved_ work its my own fault for not saving the documents
Ur living in the past man!
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Check out my blog! )
|)””’) piHole.org
-”-”-
|
|
|
|
|
Cristian Amarie wrote: My 0.2.
You know 0.2 dollars is actually 20 cents, right?
|
|
|
|