473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

large ArrayList causes program to crash

I have a small class of data values made up of ints and bools
totalling 25 bytes. Each of these 25 byte nodes is stored in another
class as an ArrayList with a few more ints. Typically there are around
400 nodes stored in each of these segment classes. - which makes each
segment occupy around 10KB.

I use further ArrayList to store around 30,000 of these segments,
which are read in from a file.

If a read in a file that contains 10,000 of these segments with the
node data, everything *seems* OK. Try reading 15,000 and the program
gets very slow at populating the ArrayList. Try the full 30,000, and
the program just goes on for ever trying to load the data in off the
disk, eventually warning me of low virtual memory.

The PC I'm developing on has 256MB of RAM. It looks to me as if too
much data is being stored to the stack instead of the heap, which I
would have thought would have been more than capable of storing 300MB
of segment data.

All I'm doing is creating instances of the classes, as the data is
read from the disk, then Adding them to the ArrayLists.

1) Does anyone have any advice as to if the ArrayList should be able
to handle this amount of data?
2) Are there any little gotchyas to watch out for when working with
large ArrayLists in c#?

Many thanks

Stuart
Nov 16 '05 #1
4 2031

"Stuart" <st*****@yahoo.com> wrote in message
news:d9**************************@posting.google.c om...
I have a small class of data values made up of ints and bools
totalling 25 bytes. Each of these 25 byte nodes is stored in another
class as an ArrayList with a few more ints. Typically there are around
400 nodes stored in each of these segment classes. - which makes each
segment occupy around 10KB.

I use further ArrayList to store around 30,000 of these segments,
which are read in from a file.

If a read in a file that contains 10,000 of these segments with the
node data, everything *seems* OK. Try reading 15,000 and the program
gets very slow at populating the ArrayList. Try the full 30,000, and
the program just goes on for ever trying to load the data in off the
disk, eventually warning me of low virtual memory.

The PC I'm developing on has 256MB of RAM. It looks to me as if too
much data is being stored to the stack instead of the heap, which I
would have thought would have been more than capable of storing 300MB
of segment data.

All I'm doing is creating instances of the classes, as the data is
read from the disk, then Adding them to the ArrayLists.

1) Does anyone have any advice as to if the ArrayList should be able
to handle this amount of data?
2) Are there any little gotchyas to watch out for when working with
large ArrayLists in c#?

Your managed heap will be at least 300mb large, but possibly larger
depending on how it gets collected. Then the memory required for the CLR
and the OS and other programs. I think 256M of ram is far too little to run
this program. My guess is that running this program and Visual Studio, you
will need total virtual memory of around 700 megs. For which you should
have at least 512meg of ram.

David
Nov 16 '05 #2
Sutart,

I think that storing this much information is a little much. If
anything, would it be possible to store the data in a database of some sort,
where you could get what you need, instead of just loading everything at
once? Or rather, could you just load what you need in segments, and process
it and then dispose of it? It seems a little much to be loading all of this
at one time.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Stuart" <st*****@yahoo.com> wrote in message
news:d9**************************@posting.google.c om...
I have a small class of data values made up of ints and bools
totalling 25 bytes. Each of these 25 byte nodes is stored in another
class as an ArrayList with a few more ints. Typically there are around
400 nodes stored in each of these segment classes. - which makes each
segment occupy around 10KB.

I use further ArrayList to store around 30,000 of these segments,
which are read in from a file.

If a read in a file that contains 10,000 of these segments with the
node data, everything *seems* OK. Try reading 15,000 and the program
gets very slow at populating the ArrayList. Try the full 30,000, and
the program just goes on for ever trying to load the data in off the
disk, eventually warning me of low virtual memory.

The PC I'm developing on has 256MB of RAM. It looks to me as if too
much data is being stored to the stack instead of the heap, which I
would have thought would have been more than capable of storing 300MB
of segment data.

All I'm doing is creating instances of the classes, as the data is
read from the disk, then Adding them to the ArrayLists.

1) Does anyone have any advice as to if the ArrayList should be able
to handle this amount of data?
2) Are there any little gotchyas to watch out for when working with
large ArrayLists in c#?

Many thanks

Stuart

Nov 16 '05 #3
Hi Stuart:

See inline:

On 30 Sep 2004 11:39:01 -0700, st*****@yahoo.com (Stuart) wrote:
I have a small class of data values made up of ints and bools
totalling 25 bytes. Each of these 25 byte nodes is stored in another
class as an ArrayList with a few more ints. Typically there are around
400 nodes stored in each of these segment classes. - which makes each
segment occupy around 10KB.

I use further ArrayList to store around 30,000 of these segments,
which are read in from a file.

If a read in a file that contains 10,000 of these segments with the
node data, everything *seems* OK. Try reading 15,000 and the program
gets very slow at populating the ArrayList. Try the full 30,000, and
the program just goes on for ever trying to load the data in off the
disk, eventually warning me of low virtual memory.

If the program exhausts physical memory, there is going to be a
performance impact. The OS will swap more pages in and out of RAM and
the system becomes disk-bound.
The PC I'm developing on has 256MB of RAM. It looks to me as if too
much data is being stored to the stack instead of the heap, which I
would have thought would have been more than capable of storing 300MB
of segment data.

If you are creating a new instance of a class, all the space allocated
is on the heap, even for the class fields which are value types like
int and bool.
All I'm doing is creating instances of the classes, as the data is
read from the disk, then Adding them to the ArrayLists.

1) Does anyone have any advice as to if the ArrayList should be able
to handle this amount of data?
The ArrayList can handle this amount of data, but I wouldn't try it on
a machine with 256MB of RAM. This is pretty unfriendly behavior to the
rest of the system even if more RAM is present. Is there any chance
you can do processing in smaller chunks?
2) Are there any little gotchyas to watch out for when working with
large ArrayLists in c#?


If the initial capacity of the ArrayList is not set, it defaults to a
capacity of 16. If a new node is added to the ArrayList and it needs
to expand, it will double capacity and the internal array is
reallocated. Reallocations are 'relatively' expensive, meaning it
probably won't make a big difference in your application anyway
because of the low memory situation.

--
Scott
http://www.OdeToCode.com/

Nov 16 '05 #4
Thanks guys for the response!

I tested the application without the VS running on a machine 512MB at the
program ran correctly, albeit a little sluggish. I used CLR Profiler to
watch the data appearing on the heap too.

You have all confirmed one of the things I was thinking, in that there is
too much data in the application, even when it is all on the managed heap.

I will look to segmenting the data as suggested. I guess I could put it all
out to a temp file that I can access quickly as the application is running.
I think I have seen this sort of thing done with a commercial audio editing
program I have.

Thanks again.

Stuart
"Stuart" <st*****@yahoo.com> wrote in message
news:d9**************************@posting.google.c om...
I have a small class of data values made up of ints and bools
totalling 25 bytes. Each of these 25 byte nodes is stored in another
class as an ArrayList with a few more ints. Typically there are around
400 nodes stored in each of these segment classes. - which makes each
segment occupy around 10KB.

I use further ArrayList to store around 30,000 of these segments,
which are read in from a file.

If a read in a file that contains 10,000 of these segments with the
node data, everything *seems* OK. Try reading 15,000 and the program
gets very slow at populating the ArrayList. Try the full 30,000, and
the program just goes on for ever trying to load the data in off the
disk, eventually warning me of low virtual memory.

The PC I'm developing on has 256MB of RAM. It looks to me as if too
much data is being stored to the stack instead of the heap, which I
would have thought would have been more than capable of storing 300MB
of segment data.

All I'm doing is creating instances of the classes, as the data is
read from the disk, then Adding them to the ArrayLists.

1) Does anyone have any advice as to if the ArrayList should be able
to handle this amount of data?
2) Are there any little gotchyas to watch out for when working with
large ArrayLists in c#?

Many thanks

Stuart

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Hal Styli | last post by:
Hello, Can someone please help. I need to use a large array and I'm not sure when one should use (A) and when one should use (B) below:- #define MAX 10000000 (A) int x;
11
by: Gnik | last post by:
I created a C# application with some large string constants and whenever I try to build the solution the compiler crashes with no error message. On further analysis the problem seems to occur when...
13
by: Larry Woods | last post by:
I am creating a "from-to" set of listboxes where the "left" listbox had a list of values and I want to be able to select these values, 1 at a time, and move them into a "right" listbox, removing...
17
by: byte8bits | last post by:
How does C++ safely open and read very large files? For example, say I have 1GB of physical memory and I open a 4GB file and attempt to read it like so: #include <iostream> #include <fstream>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.