About RAII and GC...?
Witold Baryluk
baryluk at smp.if.uj.edu.pl
Tue Jul 31 12:05:43 PDT 2007
Nick Sabalausky wrote:
> Now, maybe I'm misunderstanding RAII, but as I understand it, RAII
> guarantees that allocated memory (or whatever resource) gets freed
> automatically whenever the owning object goes out of scope.
>
> So that seems to indicate to me that RAII is not only more general than GC
> (ie, can work for more than just memory) but also lacks any overhead of
> having a GC (aside from the usual overhead of freeing a resource). Thus,
> RAII can effectively replace the use of a GC.
You are probably right. If absolutely all variables (with references types)
is declared with scope, then they will be destroyed explicitly and GC will
have probably nothing to do. But you will need to write allocators for this
types of variables, because compiler will use GC allocator (but will free
memory explicitly like with delete) if not.
More information about the Digitalmars-d
mailing list