473,320 Members | 2,080 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,320 software developers and data experts.

Memory consumption of generic lists

Hi guys!

I use a generic list which, once filled, will not change. It contains a
few 100'000 entries, so I'd like to limit its memory consumption. If I
set its capacity to its count after filling it, does the extra unused
memory (due to its probably high capacity by this time) get freed up do
I have to copy it into a new list where I set the capacity before
filling?
It is not possible to know how many entries it will contain before
filling starts.

Thanks in advance for any answers!
BTW: Is there a good online resource for C# out there? VisualStudio's
helpfile is really lousy...

Cheerio,
Hannes

Oct 31 '06 #1
3 2043
Well, depending on what functionality of the list you need, you could always
use a List<Tto *fill* the data, then call .ToArray() and just keep the
array. This makes it very explicit that it is intended to be fixed size.

When 3.0 comes out, I *believe* that LINQ will ensure that even arrays
(since they support IEnumerable) have a greater range of query methods. We
shall see ;-p

Re the C# resource... google is your friend; it depends what level you
want... "Ecma-334" is a very good reference, for instance...

Marc
Oct 31 '06 #2
call .ToArray()

Ooh, sweet! Exactly what I wanted. Thank you!
Re the C# resource... "Ecma-334"
I'll give that a shot, thanks.

Cheerio,
Hannes

Oct 31 '06 #3
Hannes,

You can call the TrimExcess method to compact the list. 100,000 is a
lot of items to store in memory. I don't know how big each item is,
but if they're really big you might want to consider using a
compression strategy.

Brian

Hannes wrote:
Hi guys!

I use a generic list which, once filled, will not change. It contains a
few 100'000 entries, so I'd like to limit its memory consumption. If I
set its capacity to its count after filling it, does the extra unused
memory (due to its probably high capacity by this time) get freed up do
I have to copy it into a new list where I set the capacity before
filling?
It is not possible to know how many entries it will contain before
filling starts.

Thanks in advance for any answers!
BTW: Is there a good online resource for C# out there? VisualStudio's
helpfile is really lousy...

Cheerio,
Hannes
Oct 31 '06 #4

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

Similar topics

8
by: Benjamin Scott | last post by:
Hello. I attempted to build a compound dictionary: len(Lst)=1000 len(nuerLst)=250 len(nuestLst)=500 Dict={}
12
by: Anon | last post by:
Hello all, I'm hoping for some guidance here... I am a c/c++ "expert", but a complete python virgin. I'm trying to create a program that loads in the entire FreeDB database (excluding the...
7
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
81
by: Peter Olcott | last post by:
It looks like System::Collections::Generic.List throws and OUT_OF_MEMORY exception whenever memory allocated exceeds 256 MB. I have 1024 MB on my system so I am not even out of physical RAM, much...
12
by: Tony | last post by:
Hi expert, I installed DB2 v8.2 server on Solaris 9 box. When I connect to DB2 using control centre or other applications(except command line), around 12 db2sysc processes pop up and each one...
17
by: frederic.pica | last post by:
Greets, I've some troubles getting my memory freed by python, how can I force it to release the memory ? I've tried del and gc.collect() with no success. Here is a code sample, parsing an XML...
1
by: buu | last post by:
It's strange to me, but, create a dictionary and fill it with 1 mil. of some objects. then, see the memory consumption (arised, of course). then, clean the dictionary.... memory consumption is...
10
by: deciacco | last post by:
I'm writing a command line utility to move some files. I'm dealing with thousands of files and I was wondering if anyone had any suggestions. This is what I have currently: $arrayVirtualFile =...
17
by: Cesar | last post by:
Hello people. I'm having a Winform app that contains a webbrowser control that keeps navigating from one page to another permanentrly to make some tests. The problem I'm having is that after a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.