
Originally Posted by
jan_ole
For that comparison you need to know the internals of ConvertFromUnicodeToUtf8L() and here, you're only comparing the memory footprint, not the computational footprint of necessary reallocs() inside ConvertFromUnicodeToUtf8L() ( or a pre-scan, which is pretty unlikely. )
HookLogger could reveal allocations inside, if you are that interested. Anyway, so far you were complaining about memory usage. And yes, your code is wasting memory, my proposal may waste CPU cycles. There is always a tradeoff.
The "hole" theory is nice, but fails as soon as your p > 2.
Check it once more. The "hole theory" was explained using the worst case, p=4. 4 > 2 as far as I can remember.
No, sorry, didn't notice that.
I know.
I wouldn't mind the example using ConvertFromUnicodeToUtf8L() and then a simple strncpy like mechanism. I'd actually preferred that.
Something like
Code:
HBufC8 *text=CnvUtfConverter::ConvertFromUnicodeToUtf8L(aText);
str.assign(static_cast<const char*>(text->Ptr()),text->Length());
could do that (or using the similar constructor of std::string).
It will not necessarily work, I do not speak STL in fact. And it can be a problem if the string operation runs out of memory.