encoding - C++ what is worse abstracting away or converting? -
I doubt:
Or I remove my wire-type and type local string or I use something like ICU and convert when needed for local type.
I would like to give you the following example:
enum stringing {ICU_STRING, STD_STRING, MSCORLIB_STRING, nestring, ... / * you get the picture; Template & lt; Class E & gt; Square_mistress {}; The template's & lt; & Gt; Class _ MyStstring & lt; ICU_STRING & gt; {}; The template's & lt; & Gt; Class _ MyStstring & lt; NSSTRING & gt; {}; #if Defined (__ ICU_INSTALLED__) typedef _MyString & lt; ICU_STRING & gt; MyString; #Aliffer defined (__ DOT_NET__) typedIf_mustrying & lt; MSCORLIB_STRING & gt; MyString; / * ... * / #endif
Or do I use the ICU implementation in my code and convert the UnicodeString to characterencoding of that runtime.
Thank you,
Filip
Why is the string size an issue? Either you need Unicode (or at least some ASCII), and you accept additional memory requirements, or you use something like std :: string. At a quick glance, the ICU will work with UTF-8, though with a little extra work, and it is similar to ASCII while dealing with ASCII characters only. - David Thornely
Imagine the size of the string is the biggest issue, you have a string that is 100 MB in memory The last option is selected, and all the strings are in UnicodeString (ICU) Saves ... Since the code is cross-platform, some other code needs content in its format, say nssring on Mac or system. String on the DotNet platform.
You will now have to make a temporary buffer of the same size, possibly more than that (UTF 8 can take up to 6 bytes per character), run a converter on it, and then create your new string. In the process that type selected with the contents of that buffer, you end up with 3 stars, all of the same. 300+ MB is used only because a line of code wanted something in its own way ... what damage!
Now imagine that this conversion code is applied multiple times, and probably on several threads.
Are not we lucky that 64-bit has to solve all our memory problems; -)
Comments
Post a Comment