0

I am writing a simulation program, and I define a struct Node, of about 544 bytes. In the program I need to malloc millions of nodes. Each time when the maximum number reaches almost 3 million,

newnode=malloc(Node)

will return NULL. But this just takes about 250MB of memory. Can someone tell me why this happens and how to solve this problem?

UmNyobe
  • 22,539
  • 9
  • 61
  • 90
stkang
  • 11
  • maybe because your program heap size is limited? – David Haim May 12 '15 at 08:54
  • 64- or 32-bit compiler? OS 64-bit or 32-bit? – AndersK May 12 '15 at 08:57
  • Looks like the heap behaviour described in the accepted answer to [this question](http://stackoverflow.com/questions/30186079/the-maximum-malloc-space-for-visula-studio-c). The only solution appears to be to roll your own memory allocator. – Andy Brown May 12 '15 at 09:21
  • 1
    3 * 10^6 * 544 / 1024^2 = 1556.3964843750 – user1095108 May 12 '15 at 09:50
  • @TonyD. Doh! Thanks for pointing that out. [Here's the real link](http://stackoverflow.com/questions/4503276/whats-all-this-uncommitted-reserved-memory-in-my-process). Perhaps the OP can run VMMap and tell us if he sees large amounts of uncommitted but reserved memory in his process at the point of failure. – Andy Brown May 12 '15 at 09:54
  • the system for my computer is Windows 7 64-bits – stkang May 13 '15 at 04:37

0 Answers0