Reflection and serialization of C + + __c++

Source: Internet
Author: User

Gamasutra on the article is very thin: sponsored feature:behind the mirror-adding Reflection to C + + RTTI after the class declaration to join the RTTI macro is almost as standard as the various engines, Who is called C + + Rtti too weak again. Before just think oneself realizes rtti reason is dynamic_cast inefficient and object factory's need, turned off this compilation option can also reduce occupied memory Field (property) Implementation reflection must have some attribute members of the description class, This information currently sees three implementations using tool/compiler intermediate information, etc. based on C + + code to parse the build (Havok is the kind of implementation). Not recommended, see the original use of various templates + macros like Rtti to register, convenient query, the disadvantage is that it will increase the start time and memory footprint, it is difficult to step through the user mode of debugging, the need to query information to create, the code is more flexible, but relatively slow access is generally record member variables relative to class/ struct offset and size, and then calculate the memory address based on the instance pointer method has not yet seen the way to do the reflection of the engine, to the Cppreflect is implemented. The simpler the coding the better, the more complex can use the script instead of Clone to do a reflection of the other advantage is that the object can be deep copy, which is also the basic requirements of prefab/template serialization has a reflection to do the serialization is quite convenient, If it's not, it's like Gamebryo's doing it. After serializing the name (or CRC) with value, it can be compatible with the version, and is useful for the frequent changes in member properties. Binary serialization of repetitive data can be compressed, such as group For XML serialization of memory buffer, you can use Base64 encoding to inheritance data inheritance, or to copy data, that is, the data between object instances has an inheritance relationship, and only different data is saved relative to the parent instance (Template) Others Before doing delegate implementation of the only contact member function pointers, did not expect to have a member variable pointers, C + + is really profound enum and container need special treatment if you want to reflect to the propertygrid of. NET, You can use ICustomTypeDescriptor to construct dynamic property objects, or to dynamically compile build types using Reflection.Emit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.