|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
String to byte[] reloadedI 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 <adrian.rot***@ikonsoft.ro> wrote:
> I need an efficient method to convert a string object to it's byte[] Please read my reply in the C# group and try to avoid multiposting in > equivalent. 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 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: 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 |
|||||||||||||||||||||||