C ++ Object serialization and rtti

Source: Internet
Author: User

I used to think that serialization has nothing to do with rtti, but it is actually closely related.

Serialization is to convert an object into word-based throttling data for data transmission and storage. The simplest and most straightforward way is to play a standalone game in 'disks, playing and playing with a disk, the main character in the game, the npc, the map of various game elements, stored in a certain way to files, but simply say that serialization does not talk about media, from objects to binary data streams, is serialization. The purpose of serialization is to deserialize data from byte streams into objects at a certain time in the future and continue a previous software application.

Rtti generally refers to identifying dynamic type information at runtime without rtti. The deserialization process is roughly like this:

Get a piece of byte data

=>

Analyze a public header ID

=>

If identity = 1 then

Obja = new ClassA

Obja. load (the rest)

Else if identity = 2 then

Objb = new ClassB

Objb. load (...)

...

End

There will be a bunch of if else, or switch case, and there will be various types of new, or something else.

Designing a public base class won't change the above situations. Of course, the public base class is essential for a fully oriented application, unless you persuade yourself not to use object-oriented.

With rtti, You can do cool operations. deserialization can actually be done like this:

Get a piece of byte data

=>

Directly generate a base class Object Pointer

=>

Thrown to System Object Manager

=>

Identify dynamic types with rtti and drop them to their respective managers or directly participate in the logic

There is a limitation implementation in MFC. For more information, see the relevant documentation. The limitation refers to how I don't want to use the CObject base class of MFC to specify my own base class, how can I specify my memory distributor and how can I customize my storage format.

Aspx ">

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.