CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Memory crash

  1. #1
    Join Date
    Nov 2003
    Posts
    2

    Memory crash

    Hi,
    I am developing an application that consumes much memory in C#. The application needs to load many "Person" objects into memory. Each person object is heavy and contains several arrays of data. When i try to load the Person objects into memory The application crash at 1,2GB even if i have 2 GB memory in my machine.
    The persons objects are loaded with new and saved in an arrayList:

    ...
    ArrayList arrayL= new ArrayList();
    ...
    for (int i=0; i<700000; i++)
    {
    ...
    Person p = new Person(...);
    ...
    // fill the person object with data
    // fill the arrays in Person p with data
    ...
    // Add the person object to the array List
    arrayL[i] = p;

    }

    Shouldn't the application get access to the total memory? Why the application crash at ~ 1.2 GB even if i had 2 GB?
    Should i think in another solution or other way in loading the big amount of person objects into memory? In that case can anyone help with ideas

    Thanks a lot for your help

  2. #2
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    Generally it is silly idea to load so much objects into the memory at once. You DON'T need it in ANY case...

    Think about another solution. I don't know details about why do you need so much objects, what you are doing with them or where you are loading them from, so I can't suggest you another solution. May be when you discribe the problem in more details I can help...

    Even if the application doesn't crash, don't load so big amount of objects at once! It is totally wrong approach!

    martin

  3. #3
    Join Date
    Nov 2003
    Posts
    2
    Thanks for your reply,
    The application read first a population data from a DB (for each person) into memory. The population varies from 500000 to 800000 individuals. Each Person has data attached to it. And after that the population data is read into memory it will be "simulated" for each year under at least 100 years.

    So i need to keep the population data in memory under the whole simulation for performance reasons. Saving data to DB or file under simulation will decrease performance.

    I know that allocating 800000 person objects into memory with new is a wrong way to go. So i need ideas from other experiences with such problems where huge amount of data need to be loaded into memory under the whole application life.

    Thanks

  4. #4
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    Hm...
    Regarding the application crash... 2GB is maximum for amout of memory that application could get. I am talking about the virtual memory... May be, there is something in the rest of memory that could not be realeased (system resources)... Check your virtual memory size (pagefile size)...

    Regarding the application...
    Which computing you are performing on those data? Do you need all data in one Person object loaded for this? If really yes, you don't have other possibility than keep those data in DB.

    Think about some DB logic to solve the part of your simulation (may be some store procedure can do some math you need in your prog. It could result that you don't need all the persons objects in the memory).

    Even you can use something like "object pool"... So you will "virtually" read all the object into the memory. However you will define some number of object that can be "alive" and other will be stored to the harddrive and read back only when you really need them...

    Reading all the persons into the memory at once is really not good and even it is not a solution. What if the amount of person will increase to 2million??? You are not able to adress som big part of memory you need to store them (naturally on 32bit platform)...

    martin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured