Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 816073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:46:31+00:00 2026-05-15T01:46:31+00:00

I have situation in which i’m compelled to retrieve 30,000 records each to 2

  • 0

I have situation in which i’m compelled to retrieve 30,000 records each to 2 datatables.I need to do some manipulations and insert into records into the SQL server in Manipulate(dt1,dt2) function.I have to do this in 15 times as you can see in the for loop.Now I want to know what would be the effective way in terms of memory usage.I’ve used the first approach.Please suggest me the best approach.

(1)

for (int i = 0; i < 15; i++)
{
  DataTable dt1 = GetInfo(i);
  DataTable dt2 = GetData(i);
  Manipulate(dt1,dt2);
}

(OR)

(2)

DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
for (int i = 0; i < 15; i++)
{
  dt1=null;
  dt2=null;
  dt1 = GetInfo();
  dt2 = GetData();
  Manipulate(dt1, dt2);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:46:32+00:00Added an answer on May 15, 2026 at 1:46 am

    In theory, the first example is more efficient, because in the second example you start by creating two DataTable objects that won’t get used. However, these two DataTable objects contain little data, so the overhead in memory usage is minimal and almost impossible to measure.

    Trying to optimize this example for performance seems to me premature optimization, what of course is a bad thing. You should go for the most readable solution first, and only when it is too slow, optimize it.

    In your case however, the first code snippet is definitely more readable than the second one, because it is less code, the scope of variables is much shorter and you don’t needlessly reset the instances to null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation in which I need to convert a text data into
I have a situation where I need to retrieve data from a query which
I have a situation in which I need to display a string with some
I have a situation in which i need to do insert queries for every
I have a situation in which I need to dump XML into an ADODB
We have a situation in which we need to update records based on existing
I have a situation in which a managed DLL calls some unmanaged DLL. I
I have an odd situation in which I need to modify the position of
i have situation in which i have some library projects, say DataProcessors,Lib2 , included
I have this situation which is rather frustrating... I have some user controls where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.