CRYENGINE has a custom reference-counted string class CryString (declared in CryString.h) which is a replacement for the STL std::string. It should always be preferred over std::string. For convenience, string is used as a typedef for CryString
.
The following code shows good (efficient) and bad usage:
const char *szKey= "Test";
map< string, int >::const_iterator iter = m_values.find( CONST_TEMP_STRING( szKey ) ); // Good way
map< string, int >::const_iterator iter = m_values.find( szKey ); // Bad way, don't do it like this!
By using the suggested method, you avoid allocation/deallocation and copying for a temporary string object. This is a common problem for most string classes. By simply using the macro CONST_TEMP_STRING
, we trick the string class to use the pointer directly without freeing the data afterwards.
c_str()
method to access the contents of the string.c_str()
method since strings are reference-counted and a wrong string instance could be affected.CryFixedStringT
(should be preferred over static char arrays).