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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:48:22+00:00 2026-06-17T00:48:22+00:00

Is a pointer indirection (to fetch a value) more costly than a conditional? I’ve

  • 0

Is a pointer indirection (to fetch a value) more costly than a conditional?

I’ve observed that most decent compilers can precompute a pointer indirection to varying degrees–possibly removing most branching instructions–but what I’m interested in is whether the cost of an indirection is greater than the cost of a branch point in the generated code.

I would expect that if the data referenced by the pointer is not in a cache at runtime that a cache flush might occur, but I don’t have any data to back that.

Does anyone have solid data (or a justifiable opinion) on the matter?

EDIT: Several posters noted that there is no "general case" on the cost of branching: it varies wildly from chip to chip.

If you happen to know of a notable case where branching would be cheaper (with or without branch prediction) than an in-cache indirection, please mention it.

  • 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-17T00:48:23+00:00Added an answer on June 17, 2026 at 12:48 am

    This is very much dependant on the circumstances.

    1 How often is the data in cache (L1, L2, L3) or and how often it must be fetched all the way from the RAM?

    A fetch from RAM will take around 10-40ns. Of course, that will fill a whole cache-line in little more than that, so if you then use the next few bytes as well, it will definitely not “hurt as bad”.

    2 What processor is it?

    Older Intel Pentium4 were famous for their long pipeline stages, and would take 25-30 clockcycles (~15ns at 2GHz) to “recover” from a branch that was mispredicted.

    3 How “predictable” is the condition?

    Branch prediction really helps in modern processors, and they can cope quite well with “unpredictable” branches too, but it does hurt a little bit.

    4 How “busy” and “dirty” is the cache?

    If you have to throw out some dirty data to fill the cache-line, it will take another 15-50ns on top of the “fetch the data in” time.

    The indirection itself will be a fast instruction, but of course, if the next instruction uses the data immediately after, you may not be able to execute that instruction immediately – even if the data is in L1 cache.

    On a good day (well predicted, target in cache, wind in the right direction, etc), a branch, on the other hand, takes 3-7 cycles.

    And finally, of course, the compiler USUALLY knows quite well what works best… 😉

    In summary, it’s hard to say for sure, and the only way to tell what is better IN YOUR case would be to benchmark alternative solutions. I would thin that an indirect memory access is faster than a jump, but without seeing what code your source compiles to, it’s quite hard to say.

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

Sidebar

Related Questions

Is a mutex lock needed around a section of code that involves pointer indirection
I have a disappearing pointer db ; the value is properly set during creation
I have done far more C++ programming than plain old C programming. One thing
A pointer to non-const data can be implicitly converted to a pointer to const
Why does git log --decorate not display more than one tag per commit? EDIT
A pointer that is passed-in-by-reference. Why? aren't pointers just references anyways? What's really happening
When should a double indirection be used in C? Can anyone explain with a
Pointer related question. I'm going through some example code that currently reads in data
Newb question here: how can I have the value stored in Maptest[2] update along
Under what circumstances might you want to use multiple indirection (that is, a chain

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.