473,546 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Behind the scenes -- how is a DataTable implemented?

When one gets a row from a database (ie, a DataTable), the row contains a
typed value in each column. How is this typically implemented behind scenes.
I want to build this functionality myself. The reason I want to do this is
because I need an in-memory table without any of the overhead of a DataSet
or DataTable.

Thanks!
Nov 15 '05 #1
6 1745
Bill Vaughn posted an explanation to this a while back, but I think it's
been archived since they are archiving more frequently.

If I remember correctly, he said it was done via a linked list but I don't
remember the specifics (my apologies).

I'm not sure what your ultimate objective is, so it's hard to make a
suggestion, but would using a DataReader to populate a
collection/arraylist/IEnumerable object etc get you what you need. Do you
need to walk this object in both directions?
"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:BRSub.1874 77$mZ5.1356774@ attbi_s54...
When one gets a row from a database (ie, a DataTable), the row contains a
typed value in each column. How is this typically implemented behind scenes. I want to build this functionality myself. The reason I want to do this is
because I need an in-memory table without any of the overhead of a DataSet
or DataTable.

Thanks!

Nov 15 '05 #2
Hi William,
Thanks for your reply. I will try to find Bill Vaughn's post on Google
Groups.

My objective is to work with a "table" in memory. I do not need a DataReader
at all. All I need is an in-memory table that has typed columns and allows
me to get a row just as I would from a DataTable. I just don't want the
overhead of a DataTable. I do not need any DBMS functionality. Essentially,
I just need raw memory bytes that are type specific.

I could use a collection of typed array columns -- I just need to figure out
a fast way to work with row objects that would consist of one "slot" from
each of the typed array columns.

Let me know if you have any other ideas. Thanks.
Dave

"William Ryan" <do********@nos pam.comcast.net > wrote in message
news:eE******** *****@TK2MSFTNG P11.phx.gbl...
Bill Vaughn posted an explanation to this a while back, but I think it's
been archived since they are archiving more frequently.

If I remember correctly, he said it was done via a linked list but I don't
remember the specifics (my apologies).

I'm not sure what your ultimate objective is, so it's hard to make a
suggestion, but would using a DataReader to populate a
collection/arraylist/IEnumerable object etc get you what you need. Do you
need to walk this object in both directions?
"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:BRSub.1874 77$mZ5.1356774@ attbi_s54...
When one gets a row from a database (ie, a DataTable), the row contains a typed value in each column. How is this typically implemented behind

scenes.
I want to build this functionality myself. The reason I want to do this is because I need an in-memory table without any of the overhead of a DataSet or DataTable.

Thanks!


Nov 15 '05 #3
The DataTable is (more or less) a set of linked arrays--one for each column.
It is really pretty efficient. I think you may be recreating the wheel here.

--
_______________ _______________ ______
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
_______________ _______________ ____

"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:nzUub.1880 03$mZ5.1364172@ attbi_s54...
Hi William,
Thanks for your reply. I will try to find Bill Vaughn's post on Google
Groups.

My objective is to work with a "table" in memory. I do not need a DataReader at all. All I need is an in-memory table that has typed columns and allows
me to get a row just as I would from a DataTable. I just don't want the
overhead of a DataTable. I do not need any DBMS functionality. Essentially, I just need raw memory bytes that are type specific.

I could use a collection of typed array columns -- I just need to figure out a fast way to work with row objects that would consist of one "slot" from
each of the typed array columns.

Let me know if you have any other ideas. Thanks.
Dave

"William Ryan" <do********@nos pam.comcast.net > wrote in message
news:eE******** *****@TK2MSFTNG P11.phx.gbl...
Bill Vaughn posted an explanation to this a while back, but I think it's
been archived since they are archiving more frequently.

If I remember correctly, he said it was done via a linked list but I don't
remember the specifics (my apologies).

I'm not sure what your ultimate objective is, so it's hard to make a
suggestion, but would using a DataReader to populate a
collection/arraylist/IEnumerable object etc get you what you need. Do you need to walk this object in both directions?
"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:BRSub.1874 77$mZ5.1356774@ attbi_s54...
When one gets a row from a database (ie, a DataTable), the row
contains a typed value in each column. How is this typically implemented behind scenes.
I want to build this functionality myself. The reason I want to do
this is because I need an in-memory table without any of the overhead of a DataSet or DataTable.

Thanks!



Nov 15 '05 #4
Have you tried creating a DataTable from code, columns and all? Under the
scenes, all a datatable is is an 'in memory' data type. I've played with
this quite a bit, and while not professing to be an expert, at least have a
good case to make. A DataTable isn't a huge heavy object by any means. If
you are only using it to hold data, it's not notably different from using a
strongly typed collection. I created a myDataTable object that was simply a
class implementing CollectionBase. I had my own .AddRow() method which
simply added a blank object to the collection.

If I may ask, why is it that a DataTable has overhead that makes it a deal
breaker? I can tell you from personal experience that a lot of 'overhead'
is often perceived (not saying that's the case hear, just speaking from
personal experience). Remember that it's a reference type, so this can have
a HUGE performance impact depending on how you are using it. I can't
understate this point. Pass by ref or val all you want, it's a reference
type and unless you are careful, it can really cause you some problems
performance wise.

If you
"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:nzUub.1880 03$mZ5.1364172@ attbi_s54...
Hi William,
Thanks for your reply. I will try to find Bill Vaughn's post on Google
Groups.

My objective is to work with a "table" in memory. I do not need a DataReader at all. All I need is an in-memory table that has typed columns and allows
me to get a row just as I would from a DataTable. I just don't want the
overhead of a DataTable. I do not need any DBMS functionality. Essentially, I just need raw memory bytes that are type specific.

I could use a collection of typed array columns -- I just need to figure out a fast way to work with row objects that would consist of one "slot" from
each of the typed array columns.

Let me know if you have any other ideas. Thanks.
Dave

"William Ryan" <do********@nos pam.comcast.net > wrote in message
news:eE******** *****@TK2MSFTNG P11.phx.gbl...
Bill Vaughn posted an explanation to this a while back, but I think it's
been archived since they are archiving more frequently.

If I remember correctly, he said it was done via a linked list but I don't
remember the specifics (my apologies).

I'm not sure what your ultimate objective is, so it's hard to make a
suggestion, but would using a DataReader to populate a
collection/arraylist/IEnumerable object etc get you what you need. Do you need to walk this object in both directions?
"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:BRSub.1874 77$mZ5.1356774@ attbi_s54...
When one gets a row from a database (ie, a DataTable), the row
contains a typed value in each column. How is this typically implemented behind scenes.
I want to build this functionality myself. The reason I want to do
this is because I need an in-memory table without any of the overhead of a DataSet or DataTable.

Thanks!



Nov 15 '05 #5
I'm basing my performance opinion on a series of different tests I've run
over time. Each time I have tried to use DataTables, there has been a
negative performance impact. I've experimented with lots of different
things. Comments inline below.

"William Ryan" <do********@nos pam.comcast.net > wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
Have you tried creating a DataTable from code, columns and all?
Yes, that's how I always do it.
Under the
scenes, all a datatable is is an 'in memory' data type.
I understand. This is how I have used them. I was shocked to find that I
could create an ASCII file on disk much faster than I could add data to an
in-memory DataTable. Also, deleting a column from an in-memory DataTable is
extremely slow.

I've played with this quite a bit, and while not professing to be an expert, at least have a good case to make. A DataTable isn't a huge heavy object by any means. If you are only using it to hold data, it's not notably different from using a strongly typed collection.
In my experience it is much slower. I don't know why.
I created a myDataTable object that was simply a
class implementing CollectionBase. I had my own .AddRow() method which
simply added a blank object to the collection.
So how did you allow for different typed columns? Sounds like all your
columns were either not typed or of the same type.

If I may ask, why is it that a DataTable has overhead that makes it a deal
breaker? I can tell you from personal experience that a lot of 'overhead'
is often perceived (not saying that's the case hear, just speaking from
personal experience).
We're doing computationally intensive stuff. The original design (using the
standard .NET approach) took about 48 hrs of continuous running to finish a
results set. The current design, still in C#, does the same thing in 2 hrs
45 min. We've had to pay attention to performance stuff others don't need to
be concerned about.
Remember that it's a reference type, so this can have
a HUGE performance impact depending on how you are using it. I can't
understate this point. Pass by ref or val all you want, it's a reference
type and unless you are careful, it can really cause you some problems
performance wise.
Care to give an example?

If you
"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:nzUub.1880 03$mZ5.1364172@ attbi_s54...
Hi William,
Thanks for your reply. I will try to find Bill Vaughn's post on Google
Groups.

My objective is to work with a "table" in memory. I do not need a

DataReader
at all. All I need is an in-memory table that has typed columns and allows
me to get a row just as I would from a DataTable. I just don't want the
overhead of a DataTable. I do not need any DBMS functionality.

Essentially,
I just need raw memory bytes that are type specific.

I could use a collection of typed array columns -- I just need to figure

out
a fast way to work with row objects that would consist of one "slot" from each of the typed array columns.

Let me know if you have any other ideas. Thanks.
Dave

"William Ryan" <do********@nos pam.comcast.net > wrote in message
news:eE******** *****@TK2MSFTNG P11.phx.gbl...
Bill Vaughn posted an explanation to this a while back, but I think it's been archived since they are archiving more frequently.

If I remember correctly, he said it was done via a linked list but I

don't remember the specifics (my apologies).

I'm not sure what your ultimate objective is, so it's hard to make a
suggestion, but would using a DataReader to populate a
collection/arraylist/IEnumerable object etc get you what you need. Do you need to walk this object in both directions?
"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:BRSub.1874 77$mZ5.1356774@ attbi_s54...
> When one gets a row from a database (ie, a DataTable), the row

contains
a
> typed value in each column. How is this typically implemented behind
scenes.
> I want to build this functionality myself. The reason I want to do

this
is
> because I need an in-memory table without any of the overhead of a

DataSet
> or DataTable.
>
> Thanks!
>
>



Nov 15 '05 #6
I'm open to suggestions, but we have not been able to get the performance
required out of a DataTable yet. (see my reply to William Ryan)

I would certainly like to know more about the DataTable internal structure.
For example:

1. How is a row object implemented? If the DataTable is a set of linked
columns, what is the row and how can a row be made type-specific for each
cell/column?

2. How is a row inserted into a table between other rows if the DataTable is
a set of linked arrays? (Actually, in my solution I don't need to insert
between other rows, but I'm just curious how this is implemented.)

What I most need to know is how to implement a row object that is type
specific at each column and that doesn't use boxing/unboxing for primitives.

Regards,
Dave
"William (Bill) Vaughn" <bi************ **@nwlink.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The DataTable is (more or less) a set of linked arrays--one for each column. It is really pretty efficient. I think you may be recreating the wheel here.
--
_______________ _______________ ______
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights. _______________ _______________ ____

"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:nzUub.1880 03$mZ5.1364172@ attbi_s54...
Hi William,
Thanks for your reply. I will try to find Bill Vaughn's post on Google
Groups.

My objective is to work with a "table" in memory. I do not need a

DataReader
at all. All I need is an in-memory table that has typed columns and allows
me to get a row just as I would from a DataTable. I just don't want the
overhead of a DataTable. I do not need any DBMS functionality.

Essentially,
I just need raw memory bytes that are type specific.

I could use a collection of typed array columns -- I just need to figure

out
a fast way to work with row objects that would consist of one "slot" from each of the typed array columns.

Let me know if you have any other ideas. Thanks.
Dave

"William Ryan" <do********@nos pam.comcast.net > wrote in message
news:eE******** *****@TK2MSFTNG P11.phx.gbl...
Bill Vaughn posted an explanation to this a while back, but I think it's been archived since they are archiving more frequently.

If I remember correctly, he said it was done via a linked list but I

don't remember the specifics (my apologies).

I'm not sure what your ultimate objective is, so it's hard to make a
suggestion, but would using a DataReader to populate a
collection/arraylist/IEnumerable object etc get you what you need. Do you need to walk this object in both directions?
"Mountain Bikn' Guy" <vc@attbi.com > wrote in message
news:BRSub.1874 77$mZ5.1356774@ attbi_s54...
> When one gets a row from a database (ie, a DataTable), the row

contains
a
> typed value in each column. How is this typically implemented behind
scenes.
> I want to build this functionality myself. The reason I want to do

this
is
> because I need an in-memory table without any of the overhead of a

DataSet
> or DataTable.
>
> Thanks!
>
>



Nov 15 '05 #7

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

Similar topics

1
2225
by: Al Bastido via .NET 247 | last post by:
could somebody please explain to me how the datatable.newrow method works, i've been trying to figure it out for weeks. I need to emulate it myself. I can bind my datagrid to a collection of objects with no problem. But that leaves me with a fixed number of properties per object and therefore a fixed number of columns in my datagrid. I...
0
1029
by: Alfred | last post by:
I've been wanting to create a password manager for some time now and decided I'd give it a go. However, before I start I'm interested in understanding how current password managers do their mojo. Particularly, how automatically filling in values and submitting the page. I have two theories currently on the table. One, somehow the HTML...
2
1114
by: Larry Foulkrod | last post by:
I would like to learn what physically happens behind the scenes when I add references to a project and then build an assembly. If the reference were part of the mscorlib would the action taken by the compiler be different than if the reference were an old .dll file? What would that action be, are these files copied into the assembly, etc. I am...
5
1928
by: Richard | last post by:
Windows Forms, csharp, 20 rows in DataTable 14 shown in view after filter applied. For any of the 14 how do I do the datarow or something else thing to access the data in the row of the table behind the view selected on the datagrid. DataGrid only gives an index based on the 1-14 visible on the datagrid and I can't seem to update anything I...
6
7789
by: Kentamanos | last post by:
Please don't ask me why I'm doing this (trust me, it makes sense in my system), but I'd like to basically redirect requests for a certain extension (thus a handler) to an ASPX page behind the scenes. I've created a handler and set it up to handle the extension in question. In my ProcessRequest, I'd like to basically figure out which ASPX page...
3
2686
by: Thubaiti | last post by:
Hi, I have this code in my ASP.NET and I want to convert it to C# (code behind) <asp:Repeater id="subCategoryRepeater" runat="server"> <ItemTemplate> <ul> <li> <asp:HyperLink id="subCategoryHyperLink" runat="server" NavigateUrl='<%# "subcategory.aspx?subcategoryid=" +
1
3617
by: Chris Simmons | last post by:
Hello: I am trying to better understand the HttpResponse.Filter property and, although I think I "get it," I am wondering what is going on behind the scenes. I was initially stumped with the thing because all the samples I came across kept using the property as an argument to the custom filter Stream's constructor. What I then figured...
1
1138
by: mplutodh1 | last post by:
This may seem like an odd thing to do, but is there a way to blindly post to a form. By that I mean, sending data (First_Name=John) without actually having the browser go to that page? I am working on an event registration site, all of the basic registration is done in a simple ASP.NET form which saves the data to an Access DB. We need a...
3
8065
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one statement to VB.NET and this is crucial: re-implementing ISerializable.GetObjectData() in the DataTable derived class so serializing the datatable derived...
0
7504
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5360
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.