www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Hidden members of Class objects

reply Carl Sturtivant <sturtivant gmail.com> writes:
I notice that a class with no data members has a size of two 
words (at 64 bits). Presumably there's a pointer to a table of 
virtual functions, and one more. Is the Vtable first?

A COM class that inherits from IUnknown and has no data members 
has a size of three words, presumably as before plus something 
that ordinarily is in the Vtable but can't be for a COM object as 
it has its own layout of that.

What is actually in these objects using that space?
Mar 06
parent reply "H. S. Teoh" <hsteoh qfbox.info> writes:
On Wed, Mar 06, 2024 at 11:39:13PM +0000, Carl Sturtivant via
Digitalmars-d-learn wrote:
 I notice that a class with no data members has a size of two words (at
 64 bits). Presumably there's a pointer to a table of virtual
 functions, and one more. Is the Vtable first?
[...]
 What is actually in these objects using that space?
In D, there's a pointer to the vtable and another pointer to a Monitor object (used for synchronized methods). There was talk about getting rid of the Monitor field years ago, but nothing has happened yet. T -- MAS = Mana Ada Sistem?
Mar 06
parent reply Carl Sturtivant <sturtivant gmail.com> writes:
On Wednesday, 6 March 2024 at 23:45:00 UTC, H. S. Teoh wrote:
 In D, there's a pointer to the vtable and another pointer to a 
 Monitor object (used for synchronized methods).  There was talk 
 about getting rid of the Monitor field years ago, but nothing 
 has happened yet.
Very interesting: is the monitor field ever touched by compiled D code at any point nowadays? Or is it just vestigial?
Mar 06
next sibling parent kinke <noone nowhere.com> writes:
On Thursday, 7 March 2024 at 00:28:17 UTC, Carl Sturtivant wrote:
 On Wednesday, 6 March 2024 at 23:45:00 UTC, H. S. Teoh wrote:
 In D, there's a pointer to the vtable and another pointer to a 
 Monitor object (used for synchronized methods).  There was 
 talk about getting rid of the Monitor field years ago, but 
 nothing has happened yet.
Very interesting: is the monitor field ever touched by compiled D code at any point nowadays? Or is it just vestigial?
It's (lazily initialized and) used by the `synchronized(<expression>)` statement (§3 of https://dlang.org/spec/statement.html#synchronized-statement) and the mentioned `synchronized` class methods (https://dlang.org/spec/class.html#synchronized-methods).
Mar 06
prev sibling parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 07/03/2024 1:28 PM, Carl Sturtivant wrote:
 On Wednesday, 6 March 2024 at 23:45:00 UTC, H. S. Teoh wrote:
 In D, there's a pointer to the vtable and another pointer to a Monitor 
 object (used for synchronized methods).  There was talk about getting 
 rid of the Monitor field years ago, but nothing has happened yet.
Very interesting: is the monitor field ever touched by compiled D code at any point nowadays? Or is it just vestigial?
Yes its opt-in. https://dlang.org/spec/statement.html#synchronized-statement
Mar 06
next sibling parent cc <cc nevernet.com> writes:
On Thursday, 7 March 2024 at 00:38:30 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 On 07/03/2024 1:28 PM, Carl Sturtivant wrote:
 On Wednesday, 6 March 2024 at 23:45:00 UTC, H. S. Teoh wrote:
 In D, there's a pointer to the vtable and another pointer to 
 a Monitor object (used for synchronized methods).  There was 
 talk about getting rid of the Monitor field years ago, but 
 nothing has happened yet.
Very interesting: is the monitor field ever touched by compiled D code at any point nowadays? Or is it just vestigial?
Yes its opt-in. https://dlang.org/spec/statement.html#synchronized-statement
I've stumbled over the Monitor/etc sometimes writing serialization, RPC, LUA etc modules iterating over class members, looking for UDAs, after trying to separate everything out using isFunction/isTemplate/etc, on top of dealing with overload spaghetti, I now just explicitly do something dumb like this to get those edge cases out of the way: ```d static foreach (sym; __traits(allMembers, T)) static if (!["__ctor","__dtor","__xdtor","Monitor","factory"].canFind(sym)) {{ ... ```
Mar 07
prev sibling parent Carl Sturtivant <sturtivant gmail.com> writes:
On Thursday, 7 March 2024 at 00:38:30 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 Yes its opt-in. 
 https://dlang.org/spec/statement.html#synchronized-statement
As you mentioned in another thread there's handy ABI documentation for classes and interfaces just here [https://dlang.org/spec/abi.html#classes](https://dlang.org/sp c/abi.html#classes) that spells out the story.
Mar 26