Re: String to byte[] reloaded

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message news:MPG.20383e7ac4a41bc998d84a@xxxxxxxxxxxxxxxxxxxxxxx
<"David Browne" <davidbaxterbrowne no potted meat@xxxxxxxxxxx>> wrote:
> No they don't. Use Encoding.GetBytes(string, int, int, byte[], int) to
> copy the bytes into an existing byte array. Of course, you'll have to
> allocate the array at some point first... I'm currently working on a
> BufferManager class which allows buffers to be reused etc, but I'm not
> sure it's really worth it here.

Have you seen System.ServiceModel.Channels.BufferManager in .NET 3.0?

I hadn't before, to be honest. Can't say I like the idea of having to
explicitly call ReturnBuffer - my buffers allow you access to the byte
array, but implement IDisposable so you can just do:

using (IBuffer buffer = manager.GetBuffer(...))
{
byte[] bytes = buffer.Bytes;
...
}


That's handy. Though if it's a public library I would worry that it could lead to inadvertent sharing of buffers.

David

.



Relevant Pages

  • Re: How to retrieve data from Type?
    ... has no native way to allocate such a structure, other than a raw byte array. ... I don't know what's going on behind the API scenes, ... buffers are just being build dynamically in many cases. ... You could just pass a byte array, ...
    (microsoft.public.vb.general.discussion)
  • Re: Does object pooling *ever* make sense?
    ... I created an array of 1000 128K buffers. ... to allocate 100,000 128K buffers in the previous benchmark. ... tell Java, in special cases, not to zero out allocated objects? ... And it make the case of pooling only useful for primitive array. ...
    (comp.lang.java.programmer)
  • Re: Vector length in bytes
    ... An array of pointers is likely to be much smaller than the buffers it points to, but that would be the size of the array. ... The buffers OTOH are probably what you want transmit, but if you used a general memory counting algorithm, you'd likely have the size of the array of pointers included. ...
    (comp.lang.java.programmer)
  • Re: Garbage Collection Issues in long-standing services
    ... If your buffers are that small why does your working set grows to ... the pinned array should get unpinned or ... > and remove the reference to my wrapper socket class, ... > class that my wrapper socket class references that contains an ArrayList ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Any help about FIR filter algorithm
    ... > Can anyone tell me how i can get an output array from the following piece ... Please proviode memory allocations for your buffers. ... i am a bit lost about how to store my outputs in array. ...
    (comp.dsp)