Change CEF's string type?

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Change CEF's string type?

Postby magreenblatt » Tue Jul 20, 2010 10:56 pm

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
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Change CEF's string type?

Postby lodle » Wed Jul 21, 2010 5:44 am

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.
lodle
Techie
 
Posts: 32
Joined: Tue Jun 01, 2010 4:36 am

Re: Change CEF's string type?

Postby magreenblatt » Wed Jul 21, 2010 8:41 am

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.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Change CEF's string type?

Postby lodle » Fri Jul 23, 2010 11:04 pm

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?
lodle
Techie
 
Posts: 32
Joined: Tue Jun 01, 2010 4:36 am

Re: Change CEF's string type?

Postby Barium » Fri Oct 22, 2010 5:43 am

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
Barium
Newbie
 
Posts: 1
Joined: Fri Oct 22, 2010 5:36 am


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 19 guests