Why does malloc() fail when there is enough memory?

后端 未结 5 1488
遇见更好的自我
遇见更好的自我 2021-01-08 00:21

I\'m using a server with 128GB memory to do some computation. I need to malloc() a 2D float array of size 56120 * 56120. An example code is as follows:

5条回答
  •  一生所求
    2021-01-08 01:12

    This is in contrast to what others have written, but for me, changing the variable num to size_t from int allows allocation. It could be that num*num overflows the int for malloc. Doing malloc with 56120 * 56120 instead of num*num should throw an overflow error.

提交回复
热议问题