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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:55:26+00:00 2026-05-15T12:55:26+00:00

I’ve read a fair amount of stuff about efficiency of array indices vs. pointers,

  • 0

I’ve read a fair amount of stuff about efficiency of array indices vs. pointers, and how it doesn’t really matter unless you’re doing something a lot. However, I am doing this a lot.

The code in question has an array of structs. (Two different ones, for two different types actually, but whatever). Since my background is mostly in higher level languages, I defaulted to using a standard particles[i].whatever format. However, I’m not sure if that’s a good idea. For a single access, I know it doesn’t matter much, but as it stands now, one of my two main functions calls particles[i].something 8 times, and boxes[boxnum].something 4 times per particle, per iteration.

Currently it takes roughly a second to do 5000 particles and 5000 iterations. This means that I’m dealing with these accesses upwards of [including the other function] 200 million times a second. At that frequency, every little bit matters (especially since I’ll end up running this code on time on someone else’s cluster).

So my question is if it’s worth it to do something along the lines of using a pointer to the struct instead of the array access, if gcc will magically do that for me, or if it really doesn’t matter.

Thanks
~~Zeb

EDIT: OK, so compiler magic means I shouldn’t worry about it. Thanks.

You suggest a profiler, but I can’t seem to make gprof tell me any finer-grained information than the time functions take… and I already know that. Is there anything that’ll tell me that on a line-by-line basis?

  • 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-15T12:55:27+00:00Added an answer on May 15, 2026 at 12:55 pm

    If you’re iterating through the array sequentially, then you might benefit from using a pointer that increments over each loop. There is a slight bit less arithmetic than dereferencing an array. However the compilers are pretty good at optimizing things so you might not see any gain.

    Best to run a profiler to see where the problem actually lies. You may be surprised at how far you are from guessing the bottleneck.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.