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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:53:11+00:00 2026-05-23T09:53:11+00:00

Background: I am creating an efficient(hopefully) collision detection system for my game engine- it’s

  • 0

Background:
I am creating an efficient(hopefully) collision detection system for my game engine- it’s introduced a slight problem when I place large amounts of objects on the screen. My problem is this:

I will be adding and removing objects regularly and I have several manager classes that keep track of the objects at any given time which means a lot of adding and removing these objects from containers. I’ve been using vectors and deques for most of this, which is fine, however I would greatly like to upgrade the core speed of the system.

Thus the question: Which container ((STL or not) [preferably the former]) gives me the quickest (order doesn’t matter) addition, removal, and random access of elements?

I have been thinking that I’ll use a set, I will iterate through the elements, though not as often as I’ll be utilizing the other three functions.

Additional Info: essentially I’m splitting my screen into a grid of undefined size, and when an object moves I’m going to find the square that the upper left corner is currently in, then the lower right corner (assuming object is squareish of course) thus I’ll know all current grid positions the object occupies. When I do collision detection, I’ll only run checks on the grid positions with more than one object, when I check for collisions it will hopefully be much faster than my previous system =]

  • 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-23T09:53:11+00:00Added an answer on May 23, 2026 at 9:53 am

    std::set is unlikely to offer better performance: it is a node-based container, so each element requires a dynamic allocation, which can prove expensive.

    Consider sticking with std::vector: it offers constant-time random access to all elements in the sequence and constant-time insertion and removal at the end of the sequence.

    Since you say that order does not matter, you can also get constant-time removal of any element from the middle of the sequence by moving the element from the end of the sequence to have it replace the element being removed; something like this:

    void remove_element(std::vector<Entity>& v, std::vector<Entity>::iterator it)
    {
        std::vector<Entity>::iterator last_element_it = v.end() - 1;
        if (it != last_element_it) {
            using std::swap;
            swap(*it, *last_element_it);
        }
        v.erase(last_element_it);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I'm developing a game for the iPhone/iPad using cocos2d-iphone. Our engine provides the
Background Creating a wrapper function for a SQL statement. Problem A function returns 1
BACKGROUND I'm creating an AJAX chat system. It looks something like this: Mike -
Edit : I solved the problem by creating the background worker by creating it
A little background: I'm creating a set of adapters to allow communication with mobile
I am creating a simple gradient background by drawing a quad as follows: glMatrixMode
I creating a program which send newsletter with a background image. It works fine
Background Right now, I'm creating a multiple-predictor linear model and generating diagnostic plots to
I'm creating a datagridview transparent //I got the parent background image Bitmap parentBackGround =
Background : I'm currently, for my University, creating some simple apps showcasing the possible

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.