Search code examples
memory-managementreallocout-of-memory

realloc returns NULL after some time while allocating small (<500Kb) data block; there is enoug memory


Hi!

The short question is: what can be the problem?

The overall memory usage of my program (shown by task manager) is almost the same all the time (near 40 minutes) it's running, and I have near 2G more free memory.

Running on win2003r2.

Memory allocation/freeing is high enough - I need to interact with other software, preparing data for it and delete it, when it's outdated. Number of data blocks is not constant.

Thank you!


Solution

  • Typically there are only 2 reasons realloc will fail

    1. Not enough contiguous memory to satsify the request
    2. Memory corruption

    Even though there is enough overall memory in your program to satisfy the request there may not be enough contiguous memory to do so due to fragmentation. The best way to determine this is to use a tool that can report on contiguous blocks to determine if one is available to satisfy your request. I believe one of the tools in the sysinternals package does so.