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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:46:21+00:00 2026-06-11T22:46:21+00:00

char buffer[424242] = {0}; Is buffer[index] as fast as *buffer ? for (int i

  • 0
char buffer[424242] = {0};

Is buffer[index] as fast as *buffer?

for (int i = 0; i < SIZE; ++i) {
  buffer[i] = 42;
}

char* end = buffer + SIZE;
for (char* pos = buffer; pos != end; ++pos) {
  *pos = 42;
}

I guess my question is, is there any assembly instruction that can set a position in memory plus and offset to a given value in a single cycle?

LEA seems to load the address plus multiply it in this way.

  • 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-06-11T22:46:22+00:00Added an answer on June 11, 2026 at 10:46 pm

    *buffer is at least as fast as buffer[index]. Depends on index. If index == 0, they’ll be equally fast.

    As per your edit:

    char& end = buffer + SIZE;
    for (char* pos; pos != end; ++pos) {
      *pos = 42;
    }
    

    invokes undefined behavior because you don’t initialize pos.

    As per your second edit:

    Write your code for readability first, profile & possibly change only after you have some concrete results.

    for (int i = 0; i < SIZE; ++i) {
      buffer[i] = 42;
    }
    

    is way more readable, stick to it.

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

Sidebar

Related Questions

My send() and recv() looks like this: int Send(const char* buffer, int size) {
I use fread to read into a char buffer. char buffer[50]; int nbytes =
I got the following code: char buffer[2047]; int charsRead; do { if(fscanf(file, %2047[^\n]%n%*c, buffer,
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
Hey guys, here is my code. int main() { char buffer[BUFSIZE]; // define our
I have a char array of size 512 i.e char buffer [512]; This variable
My Code const int howmany = 5046; char buffer[howmany]; asm(lea buffer,%esi); //Get the address
I use this code for reading from socket : int n ; char buffer[256];
I am trying to create a function guilabel_wrap(char *buffer, int maxlen) that takes a
int main() { FILE *read_fp; char buffer[BUFSIZ + 1]; int chars_read; memset(buffer, '\0', sizeof(buffer));

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.