Rant of the day

rikki cattermole rikki at cattermole.co.nz
Tue Jan 26 02:55:30 UTC 2021


Corrected example:

import std.mmfile;

struct Database {
     string filename;
     MmFile file;

     this(string filename) {
         this.filename = filename;
         file = new MmFile(filename, MmFile.Mode.read, 0, null);
     }

     ~this() {
         if (file) {
             import core.memory : GC;
             destroy(file);
             GC.free(cast(void*)file);
         }
     }
}

//somewhere in code:
void main(string[] args) {
     Database db = Database(args[0]);
}

Note: you did not need to call GC.free. The destroy would have 
guaranteed unmapping internally. GC.free would only remove the class 
instance memory itself.


More information about the Digitalmars-d mailing list