Hi, i've noticed the leak when running the following code:

while(true)
{
XMLTranscoder* utf8Transcoder;
XMLTransService::Codes failReason;
utf8Transcoder =
XMLPlatformUtils::fgTranscService->makeNewTranscoderFor("UTF-8", failReason,
16*1024);

size_t len = XMLString::stringLen(value);
XMLByte* utf8 = new XMLByte[(len*4)+1];
unsigned int eaten;
unsigned int utf8Len = utf8Transcoder->transcodeTo(my_hebrew_string, len,
utf8, len*4, eaten, XMLTranscoder::UnRep_Throw);

utf8[utf8Len] = '\0';
string str = (char*)utf8;

delete[] utf8;
}

Also, how can i accomplish the opposite task of convert an std::string to
XMLCh* without using the regular "transcode" function?
my string contains non-english characters and i need to convert it to an
XMLCh* ... how can i do that?

Thanks again
}


David Bertoni wrote:
> 
> 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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Converting-XMLCh*-to-std%3A%3Astring-with-encoding-tf4807661.html#a13988657
Sent from the Xerces - C - Users mailing list archive at Nabble.com.

Reply via email to