Welcome, Guest. Please login or register.

Author Topic: A C++ Vectors question  (Read 3038 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: A C++ Vectors question
« on: August 27, 2007, 07:14:16 PM »
Out of curiosity, are you sure a vector is the right container for this application?

If you can kill off any enemy at any time, this implies that you will be randomly removing entries. A vector is not the best candidate for this type of use. A list based container like a queue or deque might be better.

-edit-

:lol: just read your second post...

With regard to the bug, have you tried creating a test case where you simply create a vector, remove all the elements then destroy the vector? Perhaps there's a bug in the implementation leading to a double-free or some other such oddity. This is for the GP2x, right?

At the risk of sounding heretical, I'd not use the STL for game type applications unless I knew the system was a beast and the compiler optimal...
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: A C++ Vectors question
« Reply #1 on: September 02, 2007, 11:55:49 AM »
@mdwh2

I'm not knocking the STL, it's very powerful and the containers and algorithms are usually highly optimised and I do use it.

However, I'm also realistic about things. The STL is a genereral purpose, template based library and is not the most efficient solution for everything. As with all things, it comes down to common sense. I'd never use a std::vector for a bitmask, I'd never use a std::string to hold an invarying string where a C style const char* is just as useful. I don't use C++ streams for basic IO (although if I need some complex tokenisation etc, then of course I would).

The reasons to use or not to use STL amongst game devlopers varies. Although I'm not a game developer, in my case, it comes down to many hours of examining the compiler output and profiling code. Wherever cycle-efficiency has been important I've managed to find faster solutions to just about everything it provides that I would otherwise use, but of course that is at the expense of generality.
int p; // A