473,395 Members | 1,422 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,395 software developers and data experts.

Populating an in-memory table is really slow (VS2005,c#)

Good day,

I am using c# from VS2005.

I am loading a datatable with the filenames and such from a given
directory using the following code:

arrFileList = GetAllFiles("c:\\sample", true);

dtJobs.BeginLoadData();
try
{
foreach (string sFile in arrFileList)
{
NewDataRow = dtJobs.NewRow();

sFileName = Path.GetFileName(sFile);
sFilePath = Path.GetDirectoryName(sFile);
NewDataRow.ItemArray = new object[] {sFileName, sFilePath};
dtJobs.Rows.Add(NewDataRow);
}
}
finally
{
dtJobs.EndLoadData();
}

I am using a table because I plan to use the DexExpress XtraGrid.

But for testing there are only 20 or some files in the directory and
yet this method is rather slow. Is there a better way to populate the
table (there is a timer and the data will be refreshed on a regular
basis).

The loading of the table is the slow part. The directory access and
everything else is very quick.

Thanks for any ideas.

-Markus_R

Aug 17 '06 #1
2 2730
MarkusR <ma*******@gmail.comwrote:

<snip>
The loading of the table is the slow part. The directory access and
everything else is very quick.
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 17 '06 #2
Jon wrote:
>
Could you post a short but complete program which demonstrates the
problem?
Hey Jon,

Good exercise for me. I quickly found the problem that I overlooked. I
lookup the filename in a database and that was the slowdown. <doh>

I will post my database access question instead.

I am posting my example in case it helps any one populate an in-memory
table.

namespace SampleListDir
{
public partial class Form1 : Form
{
private DataTable data;

public Form1()
{
InitializeComponent();

string[] arrFileList;
string sFileName;
int i = 1;

data = new DataTable("dtJobs");
data.BeginInit();
AddColumn(data, "ID",
System.Type.GetType("System.Int32"), true);
AddColumn(data, "Filename",
System.Type.GetType("System.String"),false);
data.EndInit();

data.Clear();

this.Cursor = Cursors.WaitCursor;
data.BeginLoadData();
try
{
arrFileList =
Directory.GetFiles("C:\\WINDOWS\\system", "*.*", 0);
foreach (string sFile in arrFileList)
{
sFileName = Path.GetFileName(sFile);
data.Rows.Add(new object[] { i, sFileName});
i++;
}
}
finally
{
data.EndLoadData();
this.Cursor = Cursors.Default;
}
MessageBox.Show("done");
}

private void AddColumn(DataTable data, string name,
System.Type type, bool ro)
{
DataColumn col;
col = new DataColumn(name, type);
col.Caption = name;
col.ReadOnly = ro;
data.Columns.Add(col);
}
}
}

Thanks for you help. :)

-Markus_R

Aug 17 '06 #3

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

Similar topics

1
by: Philipp K. Janert, Ph.D. | last post by:
Dear All! I am trying to load a relatively large table (about 1 Million rows) into an sqlite table, which is kept in memory. The load process is very slow - on the order of 15 minutes or so. ...
1
by: Jaime Stuardo | last post by:
Hi all... I have a table that will never change. Specifically it's a mortality chart that I need to use to make some calculations. One column of the table is the age of the person, and other...
2
by: Gustaf Liljegren | last post by:
I'm writing a program that will query an XML file with the XmlTextReader class (the question is not specifically about XML, however). This file is very large (maybe 20 MB at most), and during...
38
by: Peteroid | last post by:
I looked at the addresses in an 'array<>' during debug and noticed that the addresses were contiguous. Is this guaranteed, or just something it does if it can? PS = VS C++.NET 2005 Express...
4
by: Simon Johnson | last post by:
Dear All, I have decided to take the big plunge and drop the Microsoft platform and use Mod_Python and Apache in it's place. I've never used Linux before this project so it's a really big...
0
by: Rain | last post by:
Does anyone have a sample code for this? I want to draw an image in memory into another image using C# and win32 gdi.. if its confusing i'll rephrase it. I want to draw many images into one image...
3
by: Chris288 | last post by:
Hi, I have a problem where our app when compiled in VS2005 runs about 50% the speed it attains in VS2003. This is an unmanaged C++ app. I have tried most combinations of the optimization and...
0
by: JM | last post by:
I'm using VS2005 SP1. It seems to me, when I used VS2003, the IDE would only insert height and width attributes in table cells if you dragged to resize a cell. Now, with VS2005, I get the style...
4
by: patelss23 | last post by:
Hello All, I have a list containing around a million integers. And I have to search this list for several million times. This really slow downs my program. I was thinking to convert this list...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.