[Issue 7972] std.file.read allocate a buffer the size of the file even when given a upper limit

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 11 13:50:07 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=7972



--- Comment #1 from tbanelwebmin at free.fr 2013-01-11 13:50:05 PST ---
OutOfMemoryError is still there in version 2.061
calling:
   read("/path/to/bigfile", 1024);

The function
   void[] read(in char[] name, size_t upTo)
is supposed to return at most "upTo" bytes,
even for a very large file.

But internally, in the Posix version,
the allocated buffer is the size of the file
(line 222:
   immutable initialAlloc = ...
 )

The fix is to consider "upTo" when computing "initialAlloc":
  immutable initialAlloc = to!size_t(min(upTo,statbuf.st_size
      ? min(statbuf.st_size + 1, maxInitialAlloc)
      : minInitialAlloc));

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list