SIGKILL while allocating memory in C++

前端 未结 2 1743
心在旅途
心在旅途 2020-12-03 21:44

I\'m developing application for an embedded system with limited memory (Tegra 2) in C++. I\'m handling NULL results of new and new[] throughout the

2条回答
  •  广开言路
    2020-12-03 22:32

    Two ideas come to mind.

    1.) Write your own memory allocation function rather than depending on new directly. You mentioned you're on an embedded system, where special allocators are quite common in applications. Are you running your application directly on the hardware or are you running in a process under an executive/OS layer? If the latter, is there a system API provided for allocating memory?

    2.) Check out C++ set_new_handler and see if it can help you. You can request that a special function is invoked when a new allocation fails. Perhaps in that function you can take action to prevent whatever is killing the process from executing. Reference: http://www.cplusplus.com/reference/std/new/set_new_handler/

提交回复
热议问题