Information about the 'magic' field in object.Object class

realhet real_het at hotmail.com
Thu Jan 16 15:28:06 UTC 2020


On Thursday, 16 January 2020 at 14:32:24 UTC, Adam D. Ruppe wrote:
> On Thursday, 16 January 2020 at 14:30:04 UTC, realhet wrote:
>> Is there a documentation about that 'magic' field?
>
> I'm pretty sure the only fields in there are pointer to vtable 
> and pointer to monitor object...
>
>> I have a really small object, only 32 bytes. At this point if 
>> I want to add a flag bit I have 3 choices:
>
> Do you need virtual functions? If not, you could probably just 
> make a struct instead.

Thank you both for the hints!

Yes I need virtual functions (this is the base class of my layout 
system: it can be a letter, a picture, or a paragraph of text.).

I've tried extern(C++) and it went down 8 bytes.

But the I tried the following:
synchronized(obj){ ... }
Compiles without a problem. Hmm...

I think I will use extern(C++) and later when I will have a big 
system to test, I will benchmark it. I'm sure that Monitor 
functionality is not needed for these objects, so that extra 8 
bytes will worth it.

Update:
- All of the child classes needed to be marked with extern(C++)
- static class members are not supported, only __gshared static.
- passing a delegate to a constructor of this class expects a 
(extern(C++) delegate) too.
- Internal compiler error: string[string] can not be mapped to C++

So extern(C++) is not good in the current case.

I will try to use that 8 byte magic illegally, and will see if it 
is unstable or not.
I will not do any synchronization, but I think the GC will crash 
upon releasing these objects.

Thx for the help!


More information about the Digitalmars-d-learn mailing list