0

malloc returns a null pointer whenever I'm trying to allocate more than 4gb. sizeof(void*) is 8 and the machine has 256gb of physical memory of which most is unused so finding a contiguous block should be no problem. What could be the possible reasons for this?

quadprob
  • 29
  • 1
  • Show your actual malloc call. Possibly the value being passed in isn't what you expect (e.g. integer overflow). – nobody Jul 31 '15 at 13:58
  • 1
    Exactly what library for `malloc` do you use? It could be that it is misconfigured, simply recompilation of an implementation adapted for 32-bit systems or even done by a lazy programmer that didn't want to bother with larger blocks. – skyking Jul 31 '15 at 14:03
  • Also have you actually tried to confirm that the limit is actually 4Gb? Here I manage to allocate 14Gb, but not 15Gb fx. – skyking Jul 31 '15 at 14:57
  • 1
    Also what is the platform you use? Operation system, compiler ... – Vladimir Moushkov Aug 04 '15 at 13:33

1 Answers1

0

Probably due to a limitation in the malloc function. Maybe you'll find your answer in This previous post.

If you want an example of an obvious limitation, it will not give you more than the size of your RAM in terms of space.

Community
  • 1
  • 1
Peut22
  • 304
  • 1
  • 11
  • The answer in the linked question shows that it may very well give more than the size of your RAM. – skyking Jul 31 '15 at 14:04
  • Well, the second answer does agree with my idea though, so i'm not even sure anymore ! – Peut22 Jul 31 '15 at 14:08
  • I tried and managed to allocate 14Gb blocks in a loop, ran for 9361 iterations (thats 131054Gb), I have only 8Gb of RAM (AFAIK). – skyking Jul 31 '15 at 14:52