• Advertisement
Sign in to follow this  

Why do large engines use their own string class

This topic is 1326 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

While looking through the CryEngine source code I found a file CryString.h

https://github.com/adithedude007/alecmercer-origins/blob/master/Code/CryEngine/CryCommon/CryString.h

 

What I don't understand is why are they creating their own string class instead of using the std::string provided

are there benefits in doing so?

Share this post


Link to post
Share on other sites
Advertisement
The big stuff I can see in their string class that doesn't exist in the std::string class is their class is reference counted and it has a lot of helper functions that don't exist in std::string, like comparisons that don't care about case. So they apparently felt the way std::string dealt with copying strings was too costly and they also wanted to perform a lot of actions that weren't built into std::string.

Share this post


Link to post
Share on other sites

It also uses a custom allocator (presumably without the psychosis of std allocator) and supports misc things like being constructed on top of an existing char*. When I see stuff like this, I'm reminded of a comment that appears in the Fluid Studios mmgr code: "Kids, please don't try this at home. We're trained professionals here." :)

Edited by Promit

Share this post


Link to post
Share on other sites

It's worth noting that even in this case it needs to be used with care.

 

If one assigns one CryStringT object to another (ref count is 2) and uses one of them in another thread, passing it along in some data structure or something, it can wreak havoc. It's not unreasonable to be responsible for protecting your own shared data, but the COW code is not thread safe either. I believe in the standard library 2 separate string objects are not supposed to have any hidden surprises like that (though it has been a problem in the past).

Edited by achild

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement