index > .NET Framework Data Access and Storage > Memory Efficiency of DataTables

Memory Efficiency of DataTables

I'm setting up a control table in SQL, that I plan to pull into memory and use as a DataTable.

I'm declaring some of the fields in the table as varchar.

In SQL, I know I can err on the size of making the field too large, because SQL won't pad out the values.

Question: How is the size of this field handled in a DataTable in memory?

That is, if I make a field varchar(500), instead of varchar(250), will it take up the full 500 bytes in memory in the Datatable?

Or will DataTable memory management only use the space needed to hold the actual characters in the field?

Any guidance on this would be appreciated.

Thanks!
codequest
Varchar () fields become string objects in a DataTable and so only the needed memory is allocated. If a string has 10 characters then it will use 20 bytes (all strings in .NET are Unicode so it uses 2 bytes per character) + some fixed number of bytes for internal bookkeeping.
Mike Danes
reply 2

You can use google to search for other answers

 

More Articles

• SQLBulkCopy and text files.
• Determination of Business Logic location
• Datasets and SQL Server
• delete and update code at the same button cause concurrency viola...
• how to show rows in dataset when filling it? as wizzard do.
• OracleClient don't connect, OleDB with same parameters connect wi...
• So Many ADO Data Providers Which Should I Use?
• Too many connections to database
• OLEDB + SQL
• Update unable to find TableMapping error
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• boolean to bit when adding a column to a
• Suppressing display of duplicate values
• Data Access Page
• DataSet Merging
• Connection pooling
• ExecuteNonQuery not working within CLR S
• Error generating a DataSet from an Oracl
• Accessing ADO .Net DLL from C++ code
• -Using Sproc to insert rows in the DB an
• How to perform a case insensitive filter
• Desiging Data Access
• Inserting a row duplicates this row
• ADO Datareader Bug? Datareader creates a
• Using a Thread in a Web Application to A
• Database application

Hot Articles

• ConnectionString as app.config value
• Create Table in SQL - VB does not show i
• Very strange SqlCommand TimeOut question
• OCI-22053: overflow error caused when re
• Download Zip File from Sql Server
• Connecting SqlExpress from .net 1.1
• DataAdapters - Please help Im confused
• Access database problem!!!
• Replace a Select Statement
• Accessing deleted row information
• Connection Timeout
• Build connection string like COM?
• DataSet or DataReader
• Help!!! Fail to update Oracle CLOB colum
• no option to connect system.data.oledb

Recommend Articles

• How to Connect Microsoft Access database
• Any way to display images in gridview?
• Internal .Net FrameWork Data Provider Er
• Using VB2005 Express to add new rows to
• interacting applications
• TableAdapter insert/update/delete order
• Problem with calculated columns - no aut
• line ending problem
• How to import data from another database
• Missing Schema Information of Base Table
• DB_E_BADROWHANDLE(0x80040E04)]??when usi
• Can't connect to database from web servi
• Datasets and SQL Server
• Dataset Update
• access sql server database with vb