file i/o in a variety of languages
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Aug 27 14:09:55 PDT 2010
On 8/27/10 13:48 PDT, Steven Schveighoffer wrote:
> Hm.. this still allocates. We can do better than the C++ example:
>
> char[128] buf;
> char[] line = buf[];
> f.readln(line);
> f.readln(line);
>
> Which should not allocate at all in this case, and is completely safe if
> it *does* have to allocate (like if some malicious code came along and
> rewrote the file to have a 500-character first line). Try to do *that*
> with std::string :)
>
> Man D is just so cool!
Yah, nice touch. By the way, it's embarrassing that the C version is
incorrect (albeit thankfully not unsafe) on input lines longer than 128
chars.
Andrei
More information about the Digitalmars-d
mailing list