![]() |
| | #1 |
| Registered User Join Date: Feb 2002
Posts: 115
| to get experience) but this many asserts just doesn't seem right. I want to change most of these asserts to if statements so that the functions return a value on success or failure and clean up after themselves not just terminate the program. Would this be the correct way to handle things? Any help is appreciated
__________________ Dohojar Moajbuj Time is the greatest teacher, too bad it kills all its students |
| Dohojar is offline | |
| | #2 |
| Registered User Join Date: Feb 2002
Posts: 115
| Opps forgot to mention that NDEBUG is not defined in any of the files
__________________ Dohojar Moajbuj Time is the greatest teacher, too bad it kills all its students |
| Dohojar is offline | |
| | #3 |
| Code Goddess Join Date: Sep 2001
Posts: 9,664
| Assert should be used as a sanity check, it should cover for occurances that should never happen. If this programmer used it in place of if statements then you could very well have memory leaks on your hands if the program asserts situations that happen often. >Would this be the correct way to handle things? Be absolutely sure that the asserts don't perform a critical function. If you can replace most of those calls with your own assert that collects garbage without effecting the code or introducing bugs then by all means do so. Maintaining code is a job fraught with peril because you can easily create bugs while thinking that you're solving a problem. -Prelude
__________________ My best code is written with the delete key. |
| Prelude is offline | |
| | #4 |
| Registered User Join Date: Feb 2002
Posts: 115
| Thanks for the advice Prelude. I am not sure if these are sanity checks or not. Like for example, the program has to open some files and the contents of these file should match, if they dont then the program aborts. Now the problem is that a 100 files can be open at once and if one of them fails then the program never closes the ones it has already opened. That sort of thing. Does the same thing with memory allocation as well. Is memory released back to the system once a program terminates or is it still set aside in the system somewhere?
__________________ Dohojar Moajbuj Time is the greatest teacher, too bad it kills all its students |
| Dohojar is offline | |
| | #5 |
| Code Goddess Join Date: Sep 2001
Posts: 9,664
| >Is memory released back to the system once a program terminates That's system dependent. It's almost a sure thing that the big name operating systems will reclaim allocated memory when your program ends but you can't be sure of that. >if one of them fails then the program never closes the ones it has already opened That's not entirely correct, abort and exit will flush and close any open streams and files when called. It's memory allocated with malloc/calloc/realloc that you need to worry about when it comes to memory leaks. -Prelude
__________________ My best code is written with the delete key. |
| Prelude is offline | |
| | #6 |
| Registered User Join Date: Feb 2002
Posts: 115
| Thanks Prelude. I didnt know abort would do all that.
__________________ Dohojar Moajbuj Time is the greatest teacher, too bad it kills all its students |
| Dohojar is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| heap vs stack memory question | donglee | C++ Programming | 4 | 01-23-2009 04:34 PM |
| Pointer memory question | Edo | C++ Programming | 5 | 01-21-2009 03:36 AM |
| Memory question | John_L | Tech Board | 8 | 06-02-2008 10:06 PM |
| Another Dynamic Memory Question | SirCrono6 | C++ Programming | 6 | 03-02-2005 12:10 PM |
| Is it necessary to write a specific memory manager ? | Morglum | Game Programming | 18 | 07-01-2002 01:41 PM |