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 6737269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:13:45+00:00 2026-05-26T11:13:45+00:00

Suppose that it is only necessary to bind a value to a certain datamember

  • 0
  • Suppose that it is only necessary to bind a value to a certain
    datamember of a certain object when bState is true. When bState
    is false, it is not necessary, but it does not hinder either.

Which of the following pieces of code would be more efficient, and why?

(EDIT: updated, state is now a member of the object)

const int x;     
int i;
int iToBind;
Classname pObject[x];

for (; i < x; ++i) {
 if (pObject[i].bState) {
        pObject[i].somedatamember = iToBind;
    }
}

Versus:

for (; i < x; ++i) {
   pObject[i].somedatamember = iToBind;
}
  • 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-26T11:13:46+00:00Added an answer on May 26, 2026 at 11:13 am

    I would say the latter is definitely quicker. The first version has bidirectional memory access, the latter has unidirectional memory access.

    In this version:

    for (; i < x; ++i) {
      if (pObject[x].bState) {
        pObject[x].somedatamember = iToBind;
      }
    }
    

    there is a stall during the if statement as the CPU must wait for the data to be read from memory. The speed the memory is read is dependent on where the data is residing. The further from the CPU the longer it takes: L1 (fastest), L2, L3, Ram, Disk (slowest).

    In this version:

    for (; i < x; ++i) {
      pObject[x].somedatamember = iToBind;
    }
    

    there are only writes to memory. Writes to memory do not stall the CPU.

    As well as the memory access times, the latter loop has no conditional jump inside the loop. Conditional loops are a significant overhead, especially if the taken/not taken decision is effectively random.

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

Sidebar

Related Questions

Suppose I have a GUI-only application that runs on Windows and I'd like to
Suppose I'm writing a function that takes a list of integers and returns only
Suppose that two tables exist: users and groups . How does one provide simple
I need to write a control that is supposed to take only a certain
Suppose that a group wants to encrypt some information, then share the encryption key
Suppose that you have two huge files (several GB) that you want to concatenate
Suppose that I have a Java program within an IDE (Eclipse in this case).
Suppose that I have a Java class with a static method, like so: class
Suppose that there are 3 databases for Production Staging Dev As far as I
Suppose that for every Form in a WinForms application, you want to change the

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.