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

  • Home
  • SEARCH
  • 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 83223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:44:24+00:00 2026-05-10T21:44:24+00:00

I was working on some code recently and came across a method that had

  • 0

I was working on some code recently and came across a method that had 3 for-loops that worked on 2 different arrays.

Basically, what was happening was a foreach loop would walk through a vector and convert a DateTime from an object, and then another foreach loop would convert a long value from an object. Each of these loops would store the converted value into lists.

The final loop would go through these two lists and store those values into yet another list because one final conversion needed to be done for the date.

Then after all that is said and done, The final two lists are converted to an array using ToArray().

Ok, bear with me, I’m finally getting to my question.

So, I decided to make a single for loop to replace the first two foreach loops and convert the values in one fell swoop (the third loop is quasi-necessary, although, I’m sure with some working I could also put it into the single loop).

But then I read the article ‘What your computer does while you wait’ by Gustav Duarte and started thinking about memory management and what the data was doing while it’s being accessed in the for-loop where two lists are being accessed simultaneously.

So my question is, what is the best approach for something like this? Try to condense the for-loops so it happens in as little loops as possible, causing multiple data access for the different lists. Or, allow the multiple loops and let the system bring in data it’s anticipating. These lists and arrays can be potentially large and looping through 3 lists, perhaps 4 depending on how ToArray() is implemented, can get very costy (O(n^3) ??). But from what I understood in said article and from my CS classes, having to fetch data can be expensive too.

Would anyone like to provide any insight? Or have I completely gone off my rocker and need to relearn what I have unlearned?

Thank you

  • 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. 2026-05-10T21:44:24+00:00Added an answer on May 10, 2026 at 9:44 pm

    Well, you’ve got complications if the two vectors are of different sizes. As has already been pointed out, this doesn’t increase the overall complexity of the issue, so I’d stick with the simplest code – which is probably 2 loops, rather than 1 loop with complicated test conditions re the two different lengths.

    Actually, these length tests could easily make the two loops quicker than a single loop. You might also get better memory fetch performance with 2 loops – i.e. you are looking at contiguous memory – i.e. A[0],A[1],A[2]… B[0],B[1],B[2]…, rather than A[0],B[0],A[1],B[1],A[2],B[2]…

    So in every way, I’d go with 2 separate loops ;-p

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

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just add an abstract copy method. You can use covariant… May 11, 2026 at 5:41 pm
  • Editorial Team
    Editorial Team added an answer "the simplest PHP framework" does not tell us at all… May 11, 2026 at 5:41 pm
  • Editorial Team
    Editorial Team added an answer You could consider using the Google Web Toolkit, GWT, to… May 11, 2026 at 5:41 pm

Related Questions

Imagine an object you are working with has a collection of other objects associated
I am working on an .net (C#) web application. Recently a defect came my
I'm using Delphi 2007 Pro. I have a runtime package that includes a number
I was recently working on a piece of C++ code for a side project

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.