Free Republic
Browse · Search
General/Chat
Topics · Post Article

To: Utilizer
It's actually a pretty stupid example.

It makes no sense to concatenate the string in memory and then write it to disk, since in either case you will be writing the string sequentially to disk, anyway. Java, Python, C#, and other "managed" languages will always do this more slowly because their strings are immutable, which any decent coder knows.

Best approach: find out the allocation block size of a file on disk, pre-allocate one buffer of that size, memory write to that buffer, flushing the whole block to disk when it's full; this avoid the penalty of zillions of memory allocations and garbage collections and writes a block of optimal size.

In most cases, just pre-allocating a moderately sized block of memory without knowing the best block size is good enough and may even be preferable, because the underlying OS is going to optimally block IO, and probably also cache that at a secondary level.

The key point is to avoid over-allocating managed objects, and again, most good coders know to do this, even if people writing stupid research papers don't...

9 posted on 03/26/2015 8:47:16 PM PDT by FredZarguna (It looks just like a Telefunken U-47 -- with leather.)
[ Post Reply | Private Reply | To 1 | View Replies ]


To: FredZarguna
A well written version of the string concatenation test should be able to write data to the disk as fast as the disk can write data.

See Fred's example above...

12 posted on 03/26/2015 8:53:11 PM PDT by freeandfreezing
[ Post Reply | Private Reply | To 9 | View Replies ]

To: FredZarguna

Good post. I have to ask, out of all the devs you’ve run into, what percentage would you say fall into the “good coders” group?


24 posted on 03/26/2015 9:27:46 PM PDT by TheZMan (I am a secessionist.)
[ Post Reply | Private Reply | To 9 | View Replies ]

Free Republic
Browse · Search
General/Chat
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson