Benjamin Smedberg wrote:
Brodie Thiesfield wrote:

Is there any way to get direct access to a buffer in a string class
similar to the MFC CString::GetBuffer()/CString::ReleaseBuffer() pair?

terminated string into it. I want to assign this string to a nsCString
which is returned from the interface. The easiest way would be to
request the string to have the max size buffer, write the data

The "proper" way is to allocate the buffer and fill it, then use the ns[C]String .Adopt() member function. The ns[C]String class then owns the buffer and will deallocate it when deleted.
OK, that sounds easy enough.

I had found the Adopt() method, but then because I had some hassles where it seemed that the method wasn't available on all classes, I went looking for another method. It looks like it is there now though, so it seems that I must have been on drugs at the time.

If the ns[C]String in question is an |inout| or |out| argument to an XPCOM interface method, the memory allocation needs to be done with nsMemory::Alloc() and everything will be happy, right?

What do I use other times (not an IDL argument), is it best to always use nsMemory::Alloc() for ns[C]Strings?

Regards,
Brodie.


Reply via email to