Associative Arrays and Interior Pointers
fmohamed at mac.com
Sun May 10 13:26:36 PDT 2009
On 2009-05-10 20:04:40 +0200, dsimcha <dsimcha at yahoo.com> said:
> == Quote from Sean Kelly (sean at invisibleduck.org)'s article
>> dsimcha wrote:
>>> 2. Other than its abysmal interaction with the current GC and the lack of
>>> ability to iterate using ranges, the current AA implementation actually seems
>>> pretty good. One way to remedy a large portion of the GC issues without a
>>> massive overhaul of the GC would be to introduce a feature into the GC where a
>>> block of memory can be flagged as NO_INTERIOR.
>> Neat idea. Some GCs (like the Boehm GC) can be set NO_INTERIOR
>> globally, but it never crossed my mind to do this per block. For
>> certain data structures, this might be pretty useful.
> I get the impression that D's GC will always have a significant degree of
> conservatism. Of course, there's always unions, but unioning a pointer
> type w/ a
> non-pointer type is such an edge case that, if this is the only thing that's
> conservative, then the GC can be considered precise for all practical purposes.
> For now, I'd love to see this added, because it would be an extremely
> "cheap" way
> to solve a lot of annoying problems.
> A few questions:
> 1. (For Leonardo, especially): Is the GC likely to get precise enough in the
> near future that something like this would end up being considered a
> piece of cruft?
> 2. Other than that, is there any reason this should not go in?
> 3. Sean, if you're seriously thinking of putting this in in the near
> future, let
> me know so I can fix that patch, too. I did it the same way as my
> other GC patch,
> with no whitespace, so the line numbers might be screwy here, too.
Yes the idea of NO_INTERIOR was floated before, and it is a good idea
and works for 99% of the usages of AA and similar objects.
Normally it is not very different from having a GC managed wrapper
object that alloc non GC managed memory, which for example is what I do
with multidimensional arrays.
For these there isn't a big advantage in NO_INTERIOR,because basically
always you have a wrapper object, and for these wrapper objects one can
explicitly say that internal pointers are valid only if a pointer to
the AA is kept
For the AA usage these is still the 0.1% usage in which one might lose
the pointer to the AA, but still have a pointer to some of its
contents. At the moment this is legal (I think) your change would
disallow it. This might still be ok, but one should be aware of it
More information about the Digitalmars-d