Monday, May 28, 2007

Fast DataTable loading from IDataReader

I was using the Load method of DataTable to load data from IDataReader the other day, and while profiling the application I found out that this is my program bottleneck.

I've just wrote a quick & dirty function which does the same task much faster:

private static DataTable ReaderToDataTable(IDataReader reader)
{
int fieldCount = reader.FieldCount;
DataTable result = new DataTable("Query Result");
for (int i = 0; i < reader.FieldCount; i++)
{
DataColumn column = result.Columns.Add(reader.GetName(i));
column.DataType = reader.GetFieldType(i);
}

object[] row = new object[fieldCount];
while (reader.Read())
{
reader.GetValues(row);
result.Rows.Add(row);
}

return result;
}

Friday, May 25, 2007

Nepali Xbox


I took this picture last November during the "Frozen Lakes" trek, Nepal.

Friday, May 18, 2007

Creating a MOSS Demo/Test machine

I've being installing a testing virtual machine for MOSS 2007 related application. While searching the internet I've found this post which describe step by step how to install MOSS machine.

Memory Debugging in .NET applications

Long time ago I found a post regarding memory debugging in .NET applications:
Analyzing Common CLR Performance Problems

That post address lots of memory leak types, while usually I encouter memory leaks from the heap. Here's the summary how to find heap memory leaks:

1. Start the windows debugger: WinDbg (can be downloaded from here).

2. Attach to the target .NET process

3. Load the SOS module, in the WinDbg console write:
.loadby sos mscorwks

4. List all the allocated objects:
!dumpheap -stat

At this point you can break & resume the program as you wish.
Other Useful commands:
!finalizequeue - show the list of objects waiting for finalize thread
!threads - running threads
!eeheap -gc - show the object generations in the GC

Full (?) list of commands can be found here