Hidden members of Class objects

cc cc at nevernet.com
Thu Mar 7 10:27:37 UTC 2024


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)) 
{{
	...
```



More information about the Digitalmars-d-learn mailing list