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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:09:20+00:00 2026-05-28T05:09:20+00:00

Will using global variables give a speed up? In Intel’s Architecture Software Developer Manual

  • 0

Will using global variables give a speed up?
In Intel’s Architecture Software Developer Manual (about the microprocessor) it is recommended to use local variables instead of global. But, consider the following code:

void process_tcp_packets(void) {
    char tcp_data[128];

    do some stuff with the tcp_data[]....
}

void process_udp_packets(void) {
    char udp_data[128];

    do some stuff with the udp_data[]
}
void main_event_loop(void) {

    while(1) {
         if (pending_tcp_requests) {
             process_tcp_packets();
         }
         if (pending_udp_requests) {
             process_udp_packets();
         }
   }
}

When main_event_loop() is executed, the control of the flow depends on the variables “pending_tcp_requests” and “pending_udp_requests”. Both functions process_tcp_packets() and process_udp_packets(), when called, will allocate local variables at the current stack pointer. This means if the code is constantly switching both functions, the local variables will be allocated at the same memory address. Sharing the memory address between both functions will evict data from current L1 cache and slow execution.
So, by using global variables instead of local ones we can speed up execution.
Is it correct or not?

If so, is there any drawback for using global variable in this case?

  • 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-28T05:09:20+00:00Added an answer on May 28, 2026 at 5:09 am

    Global variables are very unlikely to give you a benefit over the stack in this case.

    1. “Allocating” memory on the stack is simply adding a number to the stack pointer, a ½ cycle operation.
    2. At 64kb, the L1 cache is large enough to contain many stack frames. Moreover the most recent few stack frames are (because you push params when calling a function) almost always in the cache. In fact, the region for the next frame to be allocated is usually in L1, because you’ve often just exited some other function that used it.
    3. By contrast, global variables quickly fall out of L1. Remember, the stack is touched at the beginning and end of every function (just to push the return address), and process_tcp_packets() and process_udp_packets() will both use approximately the same address space to store their locals.
    4. Sharing memory addresses between functions does not evict data from cache. On the contrary, it makes you more likely to hit cache. The more recently you have touched an address, the more likely it is to be in cache.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using C (not C++) and I'm unsure how to avoid using global variables.
I have a shell script that will let me access global variables inside the
I encountered a problem when declare some global variables using macros. Here is the
Will using PinchMedia and including Core Location frameworks make it unusable on the iPod
Will using GetComInterfaceForObject and passing the returned IntPtr to unmanaged code keep the managed
I will be using jQuery's functionality to create portlet widgets for my web application
I am a student who will be using C++ next quarter. I really enjoyed
I have a php file which I will be using as exclusively as an
I am working on a project which will be using large datasets (both 2D
I'm working on an app that will be using https, but we wanted to

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.