in reply to Memory allocation/performance issue for large strings (of binary data) under Windows.
Using Storablefreeze() on a packed scalar makes no sense at all!
Freezing is only useful for encoding data structures into single scalars.
A scalar is just a large chunk of ram with some header information, freezing it will achieve nothing useful. So just pass the scalar.
And then again, if you are having to pack the numbers you are reading from the socket, then you must be reading them in as ascii. And if once you've passed them to another thread, you are going to process them as numbers with Perl, then you are going to have to unpack them again before you can do so. So why are you packing them?
You will save (a little) space by packing them, but not so much as to be particularly significant. And given the extra overhead (time) it takes to put them through the pack/unpack, and time seems to be your limitation, don't do that. You could just concatenate (or better; overwrite a buffer with) the ascii as you read it and then split it up when you've passed it to the processing thread.
The only real advantage of packing is that it allows you to know how much space is required to hold a given number of integers. But unless you know how many you are going to read and pass, that isn't much advantage. You will still need to either: pre-allocate space larger than you ultimately will ever need; or accept that you will sometimes need to grow the buffer.
And finally, "passing a (large) scalar between threads", ineveitably means copying it. Depending upon how you "pass it", possibly 2 or more times. Better to pre-allocate a shared buffer (or two); overwrite the data directly into that buffer; and then pass a simple flag between the threads to tell the processing thread which buffer contains the data that is ready for processing.
Your mocked up test script doesn't tell me enough about your real script to allow me to offer something representative:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Memory allocation/performance issue for large strings (of binary data) under Windows.
by Anonymous Monk on Nov 30, 2009 at 06:10 UTC | |
by BrowserUk (Patriarch) on Nov 30, 2009 at 08:38 UTC |