discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: libobjc2, small objects, and custom allocation


From: David Chisnall
Subject: Re: libobjc2, small objects, and custom allocation
Date: Fri, 29 Jun 2012 21:28:06 +0100

Hi Konstantin,

Objects must be word aligned.  This is both a requirement for the small object 
support, and an ABI requirement, as the first instance variable in every word 
is the class pointer (which, as a pointer, must be word aligned in a 
structure).  If your custom allocator is not returning word-aligned memory, 
then you have a bug if you are trying to use it for Objective-C objects.

There are many things in the compiler that also assume that object allocators 
return word-aligned memory - if you're breaking this invariant then expect 
large amounts of pain.

David

On 29 Jun 2012, at 21:24, Konstantin Osipov wrote:

> Hello,
> 
> We use a custom memory allocator to allocate Objective C objects,
> and it doesn't play well with libobjc2 small objects concept.
> 
> Here's how our code looks:
> 
> @implementation Request
> + (Request *) alloc
> {
>        size_t sz = class_getInstanceSize(self);
>        id new = palloc(fiber->gc_pool, sz);
>        object_setClass(new, self);
>        return new;
> }
> 
> Unfortunately, classForObject doesn't play along with an object
> allocated this way, which leads to a crash in msg_send.
> 
> I figured (from the source) that object address got to be word-aligned to
> ensure the runtime doesn't treat it as small object. 
> 
> Is this correct? What are the chances of it breaking in the future? 
> What's the approach to memory allocation which ensures 
> custom-allocated objects are not mixed up with small objects?
> 
> Thanks,
> 
> -- 
> http://tarantool.org - an efficient, extensible in-memory data store
> 
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep


-- Sent from my Difference Engine






reply via email to

[Prev in Thread] Current Thread [Next in Thread]