Using D
Mike via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jul 11 21:49:13 PDT 2014
On Saturday, 12 July 2014 at 03:59:58 UTC, Rikki Cattermole wrote:
>
> Something I've been thinking about is an overload for with
> statement.
> E.g.
>
> with(new MyAllocator) {
> void*[256] values;
> //...
> }
>
> class MyAllocator : IGC {
> private {
> IGC prevGC;
> }
>
> void opWithIn() {
> this.prevGC = GC.getImpl();
> GC.setImpl(this);
> }
>
> void opWithOut() {
> GC.setImpl(this.prevGC);
> }
> }
>
> Of course if we added an overload that allowed for passing root
> memory blocks that can be freed (ref countered guaranteed at
> compilation), we could force them to be freed in opWithOut.
> Otherwise tell the previous GC to use it.
>
> Now I sort of mix GC and allocator up a little bit, but if it
> is done right. We could swap out the GC for an allocator and
> make it almost the same.
>
> But in saying this, this would mean we would need to have a
> rethink of how we do the GC in druntime. At least from the
> architecture point of view.
>
> This isn't the reason I thought of this, mostly because I was
> exploring how to do something like GWT nice (not really
> required but could be useful for caching output).
>
> Its a small addition, that may pay off for this kind of work
> substantially. Unless of course we already have it? I didn't
> realize that statements worked in with statements till a couple
> days ago. So if not, I would be surprised.
I think that puts convenient syntax around the basic idea.
Region-based memory management is just what I'm currently
studying. There are probably other ways to accomplish the goal:
allow the user control the allocation, lifetime, and deallocation
of the built-in types.
Mike
More information about the Digitalmars-d
mailing list