Re: Classes incompatible with weak references
Re: Classes incompatible with weak references
- Subject: Re: Classes incompatible with weak references
- From: Jean-Daniel Dupas <email@hidden>
- Date: Thu, 16 Aug 2012 10:58:57 +0200
Le 14 août 2012 à 09:09, Vincent Habchi <email@hidden> a écrit :
> Le 13 août 2012, à 23:47, Mike Abdullah <email@hidden> scripsit:
>
>> An idea I've vaguely wondered about would be turning the isa variable into a tagged pointer. If you know nothing is accessing it directly (to do so was deprecated with the modern runtime), then, say, the last 4 bits of the pointer could be used to record the retain count. Once they're used up (for those rare, highly retained
>
> Using part of pointer to do something else than record an address is perilous. I remember, once again in the old days of the 68000 on the Atari ST, which had a 24-bit external address bus (and not 20 as I wrote before on some other thread), and 32-bit internal address registers, some developers had figured out to use the MSB (unused) of these address registers (pointers) to store extra information. Now, two years later the 68020 with full 32-bit external address bus was released, and suddenly all the code relying on that trick broke on the TT and later machines…
>
Unless pointer alignment requirement changed, it is safe to use this technic. Moreover, malloc is documented to return memory properly align to be used by vector units, which required at least 16 bytes alignment, so it is safe to assume that any malloced pointer on OS X has 4 unused bits.
Not only the runtime use it (as already noted in previous posts), LLVM/clang also rely heavily on this feature to reduce memory usage.
But you are right to say that is may be fragile. If you thought about using tagged pointer to store info with your objc object pointers before 10.7, the change to the runtime and framework introduced in that release would have broke your software.
-- Jean-Daniel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden