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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:11:15+00:00 2026-05-28T08:11:15+00:00

I have been taught at school to use database with integer IDs, and I

  • 0

I have been taught at school to use database with integer IDs, and I want to know if it’s also a good way to do so in C/C++. I’m making a game, using Ogre3D, so I’d like my game code to use as few cycles as possible.

This is not the exact code (I’m using vectors and it’s about characters and abilities and such), but I’m curious to know if the line where I access the weight is going to cause a bottleneck or not, since I’d doing several array subscript.

struct item
{
    float weight;
    int mask;
    item(): mask(0) {}
}
items[2000];

struct shipment
{
    int item_ids[20];

}
shipments[10000];

struct order
{
    int shipment_ids[20];
}
orders[3000];

int main()
{
    // if I want to access an item's data of a certain order, I do:
    for (int i = 0; i < 3000; ++ i)
    {
        if (items[shipments[orders[4].shipment_ids[5]]].weight > 23.0)
            s |= (1<< 31);
    }
}

I have heard that putting data into arrays is the best way to gain performance when looping over data repeatedly, I just want to know your opinion on this code…

  • 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-28T08:11:16+00:00Added an answer on May 28, 2026 at 8:11 am

    A good optimizer should be able to compute the exact offset of the memory address each of those items. There is no dependency between loop iterations, so you should be able to get loop unrolled (SIMD processing). Looks great, IMHO. If you can avoid floats, that will also help you.

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

Sidebar

Related Questions

People use void main() /*empty parens ()*/ I have been taught to write void
I have always been taught to almost never to use goto statements in programming.
Inspired by the discussion in this question . We have all been taught that
I have been in web programming for 2 years (Self taught - a biology
I've taught myself Obj-C, and have been self-teaching Cocoa, but adding Core Data to
Introduction to the problem I have been taught about OO Analysis and Design through
I have always been taught that non-primitive types should be passed by const reference
I've been taught that "assembly" is what you write in your files, to have
For quite awhile I have been trying to make a simple game in Java
I know that there have been plenty of topics describing this topic but I

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.