No STL containers?

I don't know if this is the right forum to ask this, so feel free to move this if it isn't.

I have to ask this just out of curiosity.

I was reading through the features and I noticed that you mentioned that there are "no STL containers" in the newest Box2D version. I have to ask why? Is it because of portability? Because I always believed that STL containers would be highly portable. I understood that in the previous version std::set caused some portability issues, but to remove all of them.
STL is not available for many devices (like GP32), so it's a very good thing ^^
Thanks for pointing that out 🙂

It's hard for me to think that there are platforms available that don't have STL available, but now that you pointed it out I could already think of few.
Hi,

I just found this from another site and I was taking a look and I also noticed the "Highly portable C++ with no use of STL containers", and saw this thread and wanted to add my 2 pence.

I relise not all platforms support STL but maybe its just me but should we not being shying away from the standard just because some vendors do not support it. Infact if we wanted to be more cross platform friendly perhaps it should just be C?

I guess what I'm wondering is what the reasons of C++ with specifically avoiding STL is rather than just a plain C library.

Okay bit said:)
Is it really all that hard to write simple collections? While I wouldn't get very far in C# without List<>... it's hardly a 'required' feature. (But then again in my C library I have a LIST too so...)

I also noted that this project is highly based on struct's, which must make C++ developers queezy.
I use structs for classes that are fully public. I know it bugs some C++ programmers to see a struct with member functions, but umm, they'll get over it. 😉

I think the STL is great for high level code or prototyping. But it is not so great for a high performance physics engine. Plus there are many STL implementations out there, so I would lose a lot of control over memory usage and performance. I used the STL in Box2D Lite and some people told me that was a road-block for them.

I'm a big fan of C++ for encapsulation and polymorphism. I'm not so much a fan of templates, black box containers, RTTI, exceptions, or multiple inheritance.
The fully public structs with member functions, you might aswell be using classes there is no benefit to the struct in C++ although perhaps I am one of those C++ programmers who it bugs:P

I guess my point is still why not C, I dont think you are really getting all the benefits C++ has to offer, things like the STL, templates, polymorphism, exceptions and such.

I guess as I originally said why not straight C?

Also the performance hit of STL isnt alot, the actual memory overhead of most of the containers in the STL is very small, I guess depends what youd be using from the STL.

And with things like C++ its all about the right balance trading off performance for extensibility and such, like you mentioned exceptions, exceptions do have a performance hit however they can ensure that if something breaks that really shouldnt it doesnt fall over in a heap and start crying.

Anyway Im not telling you how you should code it, merely presenting my thoughts on the matter, your actual physics implementations rock, better than I could do at any rate:)
I would use straight C, except I use these features of C++ a lot:

- polymorphism (look at b2Shape, b2Joint, b2Contact, etc.)
- operator overloading for small vector math
- inline functions
- encapsulation (the data and the functions that operate on that data).
- simple template functions

Also, I'm a big advocate of using assertions to catch errors. Exceptions are supposed to help you deal with those errors in some way, but I have not found any use for that. I just want the code to hit the assertion and bring up the debugger so I can fix the problem.

I think it is OK to cherry pick the features of C++ you like. That said, I'm open to criticism of Box2D's code architecture and API. If you feel there is some aspect that is difficult to understand or could be improved, please let me know.
I agree with Erin, and I removed STL from the Bullet physics engine a year ago, although I'm generally a fan of such standards. If only it was properly implemented on all platforms...

Some reasons were:

- there are some buggy STL implementations that don't allow storage of aligned data members (16 byte alignment for example). Even if you write your custom allocator, there is some issue one some compilers, even some of the MSVC 2005 versions suffer from this.
- some compilers/linkers don't dead-strip properly, which means that including STL bloats the code size. This is in particular an issue on CPUs with little memory, for example Playstation 3 Cell SPUs with 256kb memory. Some STL implementation contain a lot of global variables.

I mainly used std::vector and std::set. I got rid of the std::set, and re-implemented the std::vector with a subset of the std::vector interface.
Erwin

Original thread: https://box2d.org/forum/viewtopic.php?t=10