Is there an object on given memory address?
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 12 08:27:19 PST 2015
On Thursday, 12 February 2015 at 15:53:07 UTC, Marc Schütz wrote:
> On Thursday, 12 February 2015 at 10:16:49 UTC, Ola Fosheim
> Grøstad wrote:
>> then query the GC wether the memory is still allocated.
>
> This is racy, though. Someone (or the GC) could have freed the
> object in the meantime, and a new object of potentially
> different type could have taken its place. You won't get around
> pinning it.
It will statistically work for objects that are large and have
high entropy. Just hash the fields you want to be the same. If
entropy is a problem add a unique instance id that is a large
random bit string and make sure it is cleared when the object is
released.
It's the same technique used for IDs in distributed systems under
the assumption that the probability of hardware failure is larger
than the probability of a ID collision... but you have to do the
math to be sure that the probability of failure is acceptable.
More information about the Digitalmars-d-learn
mailing list