Page 1 of 1

Change CEF's string type?

PostPosted: Tue Jul 20, 2010 10:56 pm
by magreenblatt
Hi All,

As part of porting CEF to more platforms I'm considering the possibility of moving away from std::wstring and wchar_t strings as CEF's API string type. On reason is that, on Linux, wchar_t is a 32bit value which makes these strings rather expensive on that platform. Moving away from the existing string type leaves us with at least two possibilities.

1. Create a CEF string type similar to Chromium's string16 type. This provides the most flexability for switching between various native string types but adds some implementation complexity.
2. Use UTF-8 strings. This provides a single compact string type for all platforms but will require frequent string type conversions as Chromium uses 16 bit strings internally in most cases. It will also require more care on the client side to use the strings properly.

For more information on the pros and cons of each approach see this thread: http://groups.google.com/group/chromium ... beaecf96bf

What do you think?

Regards,
Marshall

Re: Change CEF's string type?

PostPosted: Wed Jul 21, 2010 5:44 am
by lodle
Why not make a custom std string type that uses a short (16 bits) instead of wchar_t as std::string and std::wstring are really template classes any way.

Re: Change CEF's string type?

PostPosted: Wed Jul 21, 2010 8:41 am
by magreenblatt
Why not make a custom std string type that uses a short (16 bits) instead of wchar_t as std::string and std::wstring are really template classes any way.

Using a different std::wstring implementation could cause binary compatibility problems with other modules that use std::wstring.

What I like about creating our own string class is that we can then use assignment and typecast overloading to provide seamless integration with existing string types. It could be designed to work transparently with std::string, std::wstring, string16, char*, wchar_t*, char16*, WebKit::WebString, etc.

Re: Change CEF's string type?

PostPosted: Fri Jul 23, 2010 11:04 pm
by lodle
In the project im working on atm we use our own custom string class based on std::string and std::wstring that does auto conversion (makes life so much easier).


What i meant is that std::string is defined as typedef basic_string<char> string and std::wstring is defined as typedef basic_string<wchar_t> string why not define a string as typedef basic_string<short> string with its own operator overloading?

Re: Change CEF's string type?

PostPosted: Fri Oct 22, 2010 5:43 am
by Barium
lodle wrote:In the project im working on atm we use our own custom string class based on std::string and std::wstring that does auto conversion (makes life so much easier).

What i meant is that std::string is defined as typedef basic_string<char> string and std::wstring is defined as typedef basic_string<wchar_t> string why not define a string as typedef basic_string<short> string with its own operator overloading?


As magreenblatt mentions in the reply to your first post about this, this will not be completely binary compatible. Using std strings across the DLL boundary is generally not recommended, unless you are absolutely certain who will be using the dll and want to enforce a specific compiler.

You can see more about binary compatibility and why you shouldn't use std strings for this purpose in this article by Chad Austin: http://chadaustin.me/cppinterface.html