Module for manual memory management

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 4 12:15:36 PST 2015


On 2/4/15 9:13 AM, Foo wrote:
> For what it's worth, today I finished the current work. Now we will
> start working with it. If someone has critique, improvement suggestions
> or want to take some ideas, he is free to do so.
> To repeat myself: we rewrote some functionality which already existed in
> D, but were improvable. For example the existing emplace method is quite
> long, hard to understand / read and is not marked with @nogc. Since we
> want to avoid the GC wherever possible we had to rewrite it. I hope it's
> useful for someone else and that some of you guys take some ideas from it.
>
> https://github.com/Dgame/m3

Opened File.d at random:

@trusted
@nogc
char[] read(const string filename) nothrow {
     import std.c.stdio : FILE, SEEK_END, SEEK_SET, fopen, fclose, 
fseek, ftell, fread;

     FILE* f = fopen(filename.ptr, READ_BINARY);
     scope(exit) fclose(f);

     fseek(f, 0, SEEK_END);
     immutable size_t fsize = ftell(f);
     fseek(f, 0, SEEK_SET);

     char[] str = m3.m3.make!(char[])(fsize);
     fread(str.ptr, fsize, 1, f);

     return str;
}

Then stopped right there. This is nowhere near production quality - 
there is no error checking whatsoever, does more operations than 
necessary, won't work on special files etc. etc. etc.

I applaud the intention but there is a lot more work to be done on this 
before it's in reviewable form.


Andrei



More information about the Digitalmars-d mailing list