Re: String to byte[] reloaded



nano2k <adrian.rotaru@xxxxxxxxxxx> wrote:
No, they're completely different - if you get to do the allocation, you
can reuse the same buffer several times.

That's right. But in my particular case, I don't need to use the
buffer several times. I'm just forced to create an extra buffer just
to pass data to the compresion method. That's my only problem.
Unfortunately, I cannot change the compress method's signature (e.g.
to accept an MemoryStream object as input data, etc), so I thought I
will be able to adapt my code, because this is where I'm 100% in
control.

You wanted to reduce the overall memory consumption, right? So create a
buffer and reuse it, encoding different strings into the same byte
array.

Just how large are the strings you're compressing? Can you not
serialize (or pseudo-serialize) the operation so you're only
compressing a few strings at a time?

I cannot keep control on the size of the request because the request
is based on an SQL statement that could virtually return tens of megs
of data (imagine for example a report for anual activity for a
comapny). Now, because all runs inside a webservice, there can be
multiple requests of such type

If there are no bounds to the amount of data you need to compress, you
really, really should be streaming it. Grabbing into one lump is never
going to be a good option.

You *may* be able to get at the UTF-16 encoded (internal) version with
unsafe code, but I'd strongly recommend against it.
I don't know what's worst. To make sure I handle very careful such a
buffer or to risc the reliability of my webservice...

It sounds to me like you should look very carefully at the overall
architecture and your compression API.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Streaming XML
    ... This document object grows bigger and bigger while the application ... The document is used as a buffer of data, ... The first is related to memory usage. ... I want to compress it. ...
    (microsoft.public.dotnet.xml)
  • Streaming XML
    ... This document object grows bigger and bigger while the application ... The document is used as a buffer of data, ... The first is related to memory usage. ... I want to compress it. ...
    (microsoft.public.dotnet.xml)
  • Re: Why COBOL is losing the POWER struggle
    ... compress replacement operands within a buffer. ... Dashwood, 'as far as you are concerned' is not 'what the machine is ...
    (comp.lang.cobol)
  • Re: Malcolms new book - Chapter 1 review
    ... he will naturally assume that the reason for the size_t is to allow the ... function to compress an buffer that can be held in memory. ... absolutely no way, with your functions, to specify how long it is. ...
    (comp.lang.c)
  • Re: async network I/O, event channels, etc
    ... thing to userspace later when the user wants it. ... tricky lifetime and unability for userspace to inform kernel when it ... They want to know when pieces of a buffer are ... available for reuse. ...
    (Linux-Kernel)

Quantcast