locked
out of memory exception RRS feed

  • Question

  • hi,

     

       System configuration : windows 2000, 2GB RAM

       virtual memory: 2GB to 4GB(Initial - Max)

     

      when I am running my application in mfc I am getting out of memory exception.

     

      My application is consisting of a huge data and In my application I am initializing 7000000 objects and each object is holding 50 bytes.

      Before allocating the memory for 7 million objects my process size is 441MB. When I am creating 7 million objects I am getting  Out of memory exception.

     

    what could be the reason for this?

     

     

     

     

      

    Wednesday, July 11, 2007 2:31 PM

Answers

  • The user mode side of an application will normally (without the presence of certain boot flags, such as 4GT or 3GB) have 2 GB of virtual address space. That does not, however, mean that you will be able to allocate nearly 2 GB of consecutive data. The amount of data you will actually be able to store in any blob is at the mercy of data already allocated, and the fragmenting of that memory. If your process has already spent 441 MB of space, and you're trying to allocate another 350 (consecutive?) MB, that may very well fail.

     

    Rather than keeping everything in memory, could you perhaps stick it in files, and map views of those?

    Wednesday, July 11, 2007 8:20 PM
  • In addition to that kind of fragmentation, there is an per-allocation overhead for both the Windows and the CRT Heaps which is likely fixed-size and therefore large as compared to 50 bytes per object. Pool allocators are typically used to avoid that kind of overhead (which - for some reason - is sometimes also called fragmentation).

     

    -hg

    Wednesday, July 11, 2007 11:47 PM

All replies

  • The user mode side of an application will normally (without the presence of certain boot flags, such as 4GT or 3GB) have 2 GB of virtual address space. That does not, however, mean that you will be able to allocate nearly 2 GB of consecutive data. The amount of data you will actually be able to store in any blob is at the mercy of data already allocated, and the fragmenting of that memory. If your process has already spent 441 MB of space, and you're trying to allocate another 350 (consecutive?) MB, that may very well fail.

     

    Rather than keeping everything in memory, could you perhaps stick it in files, and map views of those?

    Wednesday, July 11, 2007 8:20 PM
  • In addition to that kind of fragmentation, there is an per-allocation overhead for both the Windows and the CRT Heaps which is likely fixed-size and therefore large as compared to 50 bytes per object. Pool allocators are typically used to avoid that kind of overhead (which - for some reason - is sometimes also called fragmentation).

     

    -hg

    Wednesday, July 11, 2007 11:47 PM
  • hi,

     

         Actually I tried in one sample application with the same behaviour but it's went through very fine even with 1GB RAM but when I am coming through my original application I am getting out of memory exception.

     

        From my sample application I observed that when my process size is 440 MB before allocating one more 350 MB , once it reaches the peak memory usage it restarting the memory usage from 0 and allocating the memory.

     

    Could you please tell me what actually will happen when we are running through the memory allocations?

     

       

     

     

     

     

      

    Thursday, July 12, 2007 7:09 AM
  •   hi,

     

        Here is my application.

     

     class A

    {

    //  Holding 50 bytes

    };

     

    class Collection

    {

      // which is holding class A's elements

      };

    class CollectionItr

    {

    };

     

    void main()

    {

        getdata();\\ which is taking my process to 440 MB

     

        //Now i am going to allocate more 350 MB

     

        Collection *p = new Collection(7000000);

    // while  this line executing I am running into out of memory exception

    }

     

     

     

    Thursday, July 12, 2007 7:22 AM
  • I would really urge you to reconsider the inner workings of your application. Rather than keeping large amounts of data allocated at any one time, it would be a lot better to cycle through them (ie. load when needed, or processing no more than [smaller numer of elements] at a time).

     

    For the sake of getting all pieces of the puzzle, though, could you show the contents of your Collection class?

    Thursday, July 12, 2007 7:28 AM
  • here is my collection class

     

    Collection

    {

    public:

       Collection(size_t sz):list(sz){}

    private:

       vector<A> list;

    };

     

     

     

     

    Monday, July 30, 2007 11:50 AM