String to byte[] reloaded

N

nano2k

Hi
I need an efficient method to convert a string object to it's byte[]
equivalent.
I know there are LOTS of methods, but they lack in efficiency. All
methods allocate new memory to create the byte[] array. Of course,
when memory allocation occurs, then naturally extra processing power
is needed.
To more explicit, MFC introduced a super-efficient method of dealing
with this situation. As far as I remember (I switched from MFC
to .NET
few years ago), MFC's CString class has a method with the following
signature:

byte[] GetBuffer()


This method "blocks" the CString instance until ReleaseBuffer()
method
is called. Again, maybe the method names are not quite as I remember,
but the important thing is the principle.
The marvelous result is that you may freely iterate through the
byte[]
array returned by GetBuffer() method and even modify it (with respect
to some limits, of course), and all this, without allocating new
memory.
My question is: using MemoryStream class will do the job for me? I
mean, there is a method called GetBuffer(), but will it allocate new
memory or not, as it is not stated in MS documentation.


Thanks
 
J

Jon Skeet [C# MVP]

nano2k said:
I need an efficient method to convert a string object to it's byte[]
equivalent.

Please read my reply in the C# group and try to avoid multiposting in
the future.
 
?

=?ISO-8859-2?Q?G=F6ran_Andersson?=

Please read my reply in the C# group and try to avoid multiposting in
the future.
 
N

nano2k

Sorry about that and thanks for your responses.
Anyway, is there a way to put the same question in 2 or more groups?

Thanks.


Göran Andersson a scris:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top