C++ Garbage Collecter
Per Bothner
per@bothner.com
Thu Aug 26 07:52:00 GMT 1999
Jeffrey A Law <law@cygnus.com> writes:
> But this is precisely the problem. ...
> ie, the compiler effectively does something like this:
>
> a = malloc (100)
> a -= 10
> for ( ... )
> a[10 + i] = whatever
>
> even though you wrote
>
> a = malloc (100)
> for ( ...)
> a[i] = whatever
You misunderstand. I am in favor of using (say) "gcmalloc" to
allocate gc'd objects. I am *against* having malloc become
as a wrapper for gcmalloc. Plain malloc should allocate plain
manually managed memory. So when I say malloc, I mean plain malloc,
so there is no issue in your example.
My rationale is that most applications will use lower-level libraries
that are written to use plain non-gc'd memory. It serves no purpose,
and intoduces some risk, for them to use gc'd memory. My other point
is that if you are allocating a temporary buffer with such an
easy-analyzable lifetime that you risk the compiler making it dead
and thus causing it to be prematurely free; why then you don't need
to use garbage collection for this buffer, and by using plain malloc
you remove the risk from pointer unsafety.
Again, it seems that "pointer unsafety" is a mostly hypothetical problem,
*assuming* you don't replace all your mallocs by gcmalloc, or otherwise
use gcmalloc when malloc is more appropriate.
--
--Per Bothner
bothner@pacbell.net per@bothner.com http://home.pacbell.net/bothner/
More information about the Gcc
mailing list