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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:38:33+00:00 2026-05-23T22:38:33+00:00

What should I take in consideration when developing a game in terms of fast

  • 0

What should I take in consideration when developing a game in terms of fast memory access in C++?

The memory I load is static so I should put in in a continuous block of memory right?

Also, how should I organize the variables inside structs to improve performance?

  • 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-23T22:38:34+00:00Added an answer on May 23, 2026 at 10:38 pm

    Memory Performance is extremely vague.

    I think that what you are looking for is about handling the CPU Cache as there is a factor of about 10 between an access in the cache and an access in the main memory.

    For a complete reference on the mechanisms behind the cache, you might wish to read this excellent serie of articles by Ulrich Drepper on lwn.net.

    In short:

    Aim at Locality

    You should not jump around in memory, so try (when possible) to group together items that will be used together.

    Aim at Predictability

    If your memory accesses are predictable, the CPU will likely prefetch the memory for the next chunk of work, so that it is available immediately, or shortly, after finishing the current chunk.

    The typical example is with for loops on arrays:

    for (int i = 0; i != MAX; ++i)
      for (int j = 0; j != MAX; ++j)
        array[i][j] += 1;
    

    Change array[i][j] += 1; with array[j][i] += 1; and the performance varies… at low optimization levels 😉

    The compiler should catch those obvious cases, but some are more insidious. For example, the use of Node Based containers (linked lists, binary search trees) instead of array-based containers (vector, some hash tables) may slow down the application.

    Don’t waste space… beware of false sharing

    Try to pack your structures. This has to do with alignment, and you might be wasting space due to alignment issues within your structures, which artificially inflate the structure size and waste cache space.

    A typical rule of thumb is to order the items in the structure by decreasing size (use sizeof). This is dumb, but works well. If you are more knowledgeable about the size and alignments, just avoid holes 🙂 Note: only useful for structure with lots of instances…

    However, beware of false sharing. In Multi Threaded programs, concurrent access to two variables that are close enough to share the same cache line is costly, because it involves a lot of cache invalidation and CPU battling for cache line ownership.

    Profile

    Unfortunately, this is HARD to figure out.

    If you happen to be programming on Unix, Callgrind (part of the Valgrind suite) can be run with cache simulation and identify the parts of the code triggering the cache misses.

    I guess that there are other tools, I just never used them.

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

Sidebar

Related Questions

What, if any, considerations (HTML, CSS, JavaScript) should you take when designing for Google
What is the best compression algorithm with the following features: should take less time
Are the two events the same or are there differences that we should take
I have a container div that holds two internal divs; both should take 100%
How long should it take to run ALTER DATABASE [MySite] SET READ_COMMITTED_SNAPSHOT ON I
When I am creating a new database table, what factors should I take into
I should display the bookmarks as hyperlink.so on clicking the bookmark will take me
It's known that you should declare events that take as parameters (object sender, EventArgs
Take a look at the ssl_requirement plugin. Shouldn't it check to see if you're
Should I start with Django or JavaScript?

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.