Eliminate class allocators and deallocators?

Leandro Lucarella llucax at gmail.com
Thu Oct 8 09:29:48 PDT 2009


Andrei Alexandrescu, el  7 de octubre a las 16:03 me escribiste:
> Leandro Lucarella wrote:
> >Andrei Alexandrescu, el  7 de octubre a las 15:23 me escribiste:
> >>You seem to be asserting that without additional built-in language
> >>support, manual memory management is unduly difficult. Why so?
> >
> >Because of this:
> >
> >>>>>auto x = cast(MyClass) malloc(MyClass.classinfo.init.length);
> >>>>>x.__ctor( a, b, c ); // construct
> >>>>>...
> >>>>>x.__dtor();
> >>>>>free( cast(void*) x );
> >
> >:)
> >
> >You even forgot to register your object as a root in the GC, so if your
> >MyClass has any pointers to the GC your program will blow in your face.
> >
> >If you plan to library support to ease this and avoid repetitive and
> >bug-prone work, you can ignore my complains...
> 
> I too think it would be great to add the necessary support to the
> stdlib. In fact, since you have a great deal of expertise in the matter,
> feel free to suggest API functions! They'd need to be approved by Sean
> too because probably they belong to druntime.

I think the only API change should be adding a function to call the
destructors but not GC.free() (as David suggested). Then, the other
changes are only moving operators to library code. So nothing changes much
there.

-- 
Leandro Lucarella (AKA luca)                      http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
No existe nada más intenso que un reloj, ni nada más flaco que una
bicicleta. No intenso como el café, ni flaco como escopeta.
	-- Ricardo Vaporeso



More information about the Digitalmars-d mailing list