http://qs1969.pair.com?node_id=277838


in reply to Re: append to a string or make an array? (memory and time efficiency)
in thread append to a string or make an array? (memory and time efficiency)

Good catch++.

I'm not sure I agree with you about the final join though. The OP just needs to keep the 1 to 5 "few k" chunks somewhere until he has the set. At that point he is going to transmit them.

He can just as easily write them as 5 seperate strings as 1, and avoid the need to concatenate them?

I think the most efficient way would be to pre-extend to the array to max_chanks, and then pass and store references to the chunks avoiding any need to copy or concatenate. In isolation from the code that generates the chunks, passes them to the buffering code, and finally transmits them, the whole thing is an academic exercise.

Even without my gaff, the benchmark was at best iffy.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

  • Comment on Re: Re: append to a string or make an array? (memory and time efficiency)

Replies are listed 'Best First'.
Re: Re: Re: append to a string or make an array? (memory and time efficiency)
by swkronenfeld (Hermit) on Jul 25, 2003 at 16:47 UTC
    Thanks for your help Broswer and Abigail.

    You are correct, I don't need to re-join the strings at the end, I would just modify my server to transmit each chunk in the array. However, I have no idea how long it'll take to send 5 chunks vs. 1, so the join may or may not be fair.

    Since my server is single threaded, I'll modify it to have the current user's output buffer a global variable. Any methods which produce output can just tack their output onto there (without any need for passing strings or even string references among subroutines).