pundog wrote:
Hi,
I tried the code you posted, i only modified the line in which you create
the XMLByte*, instead of using "()" i replaced it with "[]". (when i used
the () and exception was thrown when i tried to delete the XMLByte*)
Yes, that was a typo, it should have been:

XMLByte* utf8 = new XMLByte[(len * 4) + 1];


The problem i've got now, is that this code causes a memory leak.. when i
tried to run it in a "while(true)" loop, it produced a serious leak. How can
i fix it?

I have no idea why your code would be leaking. If you post a minimal sample that exhibits the problem, perhaps someone can help you.


And another thing, is it ok to convert an XMLByte* to char*? or is there a
better way for converting and XMLByte* to a std::string?

There's no problem with casting an XMLByte* to a char*. However, since you're using a std::string as a return value, the best way to do this is to use a fixed size buffer for the transcode() call, then transcode and append each buffer to the result std::string in a loop. The parameters for each call of transcode, and the return value will tell you how much of the source string has been transcoded and how many bytes have been placed in the output buffer.

Dave

Reply via email to