String to byte[] reloaded

  • Thread starter Thread starter nano2k
  • Start date Start date
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
 
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.
 
Please read my reply in the C# group and try to avoid multiposting in
the future.
 
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:
 
Back
Top