How is the TypeInfo assigned?

Benjamin Thaut via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 13 08:25:16 PST 2016


On Saturday, 13 February 2016 at 12:44:40 UTC, Tofu Ninja wrote:
> Is the TypeInfo given by typeid() guaranteed to be the same for 
> a type regardless of where I call it? I guess my question is, 
> is the TypeInfo a valid way to dynamically check types?
>
> I am implementing a message passing system for an 
> entity-component system, I was planning to use structs as 
> messages and use the TypeInfo to determine where they are 
> supposed to go. Will this cause any problems?
>
> Also will typeid() allocate? Or is the TypeInfo statically 
> allocated at compile time?
>
> Also how does shared libs affect this? Will a TypeInfo passed 
> across different libs still match up?
>
> Thanks

Yes, type infos are garantueed to have identity. You can use 
their adress to identify a type.

The linux shared library mechanism ensures that they have the 
same adress across multiple shared libraries (if all of these 
libraries are loaded into the same process)

With windows dlls there can be cases where a typeinfo is 
duplicated. But as dlls don't really work yet, I wouldn't worry 
about it.


More information about the Digitalmars-d-learn mailing list