Home All Groups Group Topic Archive Search About

String to byte[] reloaded

Author
10 Feb 2007 2:14 PM
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

Author
10 Feb 2007 4:57 PM
Jon Skeet [C# MVP]
nano2k <adrian.rot***@ikonsoft.ro> wrote:
> 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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
10 Feb 2007 6:27 PM
Göran_Andersson
Please read my reply in the C# group and try to avoid multiposting in
the future.

--
Göran Andersson
_____
http://www.guffa.com
Author
12 Feb 2007 8:51 AM
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:
Show quote
> Please read my reply in the C# group and try to avoid multiposting in
> the future.
>
> --
> Göran Andersson
> _____
> http://www.guffa.com

AddThis Social Bookmark Button