c++ - Side effects of exit() without exiting? -
if application runs out of memory, re-run changed parameters. have malloc
/ new
in various parts of application, sizes of not known in advance. see 2 options:
- track memory allocations , write restarting procedure deallocates before re-running changed parameters. (of course, free memory @ appropriate places if no errors occur)
- restarting application (e.g.,
winexec()
on windows) , exiting
i not thrilled either solution. did miss alternative maybe.
thanks
simplicity rules: restart app different parameters.
it hard either track down allocs/deallocs , clean memory (just forget minor blocks inside bigger chunks [fragmentation] , still have problems rerun class), or introduce own heap-management (very clever people have invested years bring nedmalloc etc live, not fool illusion easy task).
so:
- catch "out of memory" somehow (signals, or
std::bad_alloc
, or whatever) - create new process of app:
- windows:
createprocess()
(you canexit()
program after this, cleans allocated resources you) - unix:
exec()
(replaces current process completely, "cleans memory" you)
- windows:
- done.
Comments
Post a Comment