|
From: | Xavier Glattard |
Subject: | Re: ABI Compatibility (was Re: Installation woes for the average user...) |
Date: | Tue, 10 Mar 2009 11:28:43 +0100 |
User-agent: | Thunderbird 2.0.0.16 (X11/20080707) |
Riccardo Mottola a écrit : (...)
David Chisnall wrote:
(...)
Yes, this appears to me the "least hurting" path. But I laready dislike. If we really need, this should be the road.If you make private ivars into a structure and make a pointer to this an ivar, you add an extra malloc for every +alloc (expensive) and you add an extra load for ever ivar access.That is an abomination.
Another stupid question : the memory allocation function accepts an 'extraBytes' parameter. These bytes are allocated _after_ the instance bytes by the same 'malloc' call. Couldn't this system be adapted to ivar storage ? The extra storage is at self+1 : no need for an additional pointer, and no extra load for ivar access.
@interface NSObject (ExtraMemory) + (id) allocWithZone: (NSZone*)zone extra: (size_t) extraBytes; @end ---- Usage typedef struct _LibraryClass_ext_st { int ivar1; int ivar2; } _LibraryClass_ext; #define LIBRARYCLASS_EXTRA(obj) ((_LibraryClass_ext*)((obj)+1))) @implementation LibraryClass - (id) allocWithZone: (NSZone*)z { return [self allocWithZone: z extra: sizeof(_LibraryClass_ext)]; } - (int) var1 { return LIBRARYCLASS_EXTRA(self)->ivar1; } @end
[Prev in Thread] | Current Thread | [Next in Thread] |