c++ - Recovering from out of memory failure -
i using memory pool create lot of objects. objects derive base class has new/delete on ridden use memory pool, call pool.allocate(size).
what when pool runs out of memory (there still available memory in system function) set beginning. thinking of setting label right after main , goto label when allocation fails, reset pool , start again.
all non stack allocation handled memory pool. sensible way achieve this? there gonna problems down line?
edit:
this running on embedded platform no os no exceptions. trying achieve controlled restart instead of crash out of memory. pool big enough hold calculations, trying have controlled crash in case functions goes awry.
there no state saved run run. trying achive process of hitting reset button software. can reset start of main notify app restart.
i once did similar thing using setjmp()/longjmp()
. it's not perfect or devoid of problems, but, part works. like:
jmp_buf g_env; int main() { int val = setjmp(g_env); if (val) { // restarting, need } // initialize program , go work } /// want restart: longjmp(g_env, 101); /// 101 or other "error" code
this goto
really, so, remember cleanup yourself.
Comments
Post a Comment