[Mono-dev] Embedded: storing extra data on objects?

Robert Jordan robertj at gmx.net
Tue Mar 31 05:14:00 EDT 2009


David Mitchell wrote:
> When embedding mono, is there a way to store a little bit of extra
> information (pointer-sized) along with a MonoObject (or similar structure)?
> 
> My scenario is that I have unmanaged wrappers for managed objects, and I¹d
> like to ensure that there is never more than one unmanaged wrapper per
> object (and also be able to get the unmanaged wrapper if all I have is the
> object). I¹m sure I know that I could use a hash table for this, and that
> may end up being what I do, but actually storing the pointer on the
> MonoObject seems more natural, in my case.

I wonder why your wrapper must have 1:1 relationship with the object
it wraps.

Supposing you really need this 1:1 relationship, how do you handle the
liveness of the wrapper? If there is only one pointer to its instance,
it will go away together with the MonoObject when the latter gets
garbage collected, so you won't be able to free it.

Robert



More information about the Mono-devel-list mailing list