perpetual: new module for mapping file into memory

Sergei Degtiarev via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Aug 18 07:32:16 PDT 2015


On Tuesday, 18 August 2015 at 06:52:47 UTC, Dmitry Olshansky 
wrote:
> What I don't like is perpetual being a class - too bad as it 
> won't honor scoping and destructor may or may not be called. 
> Just make it a struct.
Why do you think the destructor may not be called? It is, and it 
syncs memory and unmaps the file. Making perpetual a struct would 
require implementing reference counting or disabling copying, and 
all such staff. In my opinion, perpetual should definitely have 
reference semantics, this is exactly a point where D shines.


> Also type should be Perputal, then perpetual is helper function 
> that creates it then by means of IFTI type may be deduced. I 
> suggest the following API:
>
> // all parameters after file are either T itself
> auto p = perpetual("file-name", 42);// would deduce T=int
>
> // or args to T:
> struct RGB{ int r,g,b; }
> // if not in file use RGB(1,2,3)
> auto p = perpetual!RGB("file-name", 1, 2, 3);
Right, just forgot. Will do, thanks.




More information about the Digitalmars-d-announce mailing list