Under what circumstances can malloc return NULL?

前端 未结 9 1740
陌清茗
陌清茗 2020-12-23 14:17

It has never happened to me, and I\'ve programming for years now.

Can someone give me an example of a non-trivial program in which malloc will actually

9条回答
  •  半阙折子戏
    2020-12-23 14:59

    Any program at all written in c that needs to dynamically allocate more memory than the OS currently allows.

    For fun, if you are using ubuntu type in

     ulimit -v 5000
    

    Any program you run will most likely crash (due to a malloc failure) as you've limited the amount of available memory to any one process to a pithy amount.

提交回复
热议问题