Bug 4859 – Another File.byChunk()

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-09-13T04:18:00Z
Last change time
2014-02-24T10:27:25Z
Assigned to
andrei
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-09-13T04:18:49Z
std.stdio.File.byChunk reuses the content of buffer across calls, but I think the first call performs an allocation. Tango has shown that an important factor for the performance of D programs is to minimize memory allocations. So an overloaded byChunk may be added with a signature similar to (so the older byChunk() is not removed, this is added): chunks byChunk(void[] buffer); So you may use it like this and avoid the first memory allocation too: ubyte[4096] buffer; foreach (ubyte[] chunk; stdin.byChunk(buffer[])) { ... use chunk ... }
Comment #1 by andrei — 2013-03-12T20:48:08Z
Comment #2 by github-bugzilla — 2013-12-25T02:01:27Z
Comment #3 by monarchdodra — 2014-02-24T10:27:25Z
*** Issue 12107 has been marked as a duplicate of this issue. ***