Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

c++ - Is it possible to initalize multiple data members with one stream read call?

i am working for a class serialization implementation and for now i wonder if i can stream a binary buffer from a opened seriallized file into a memory address within a class with saved calculated size and make whole block of data members done, and for that i definitely need data members address to be sequential (end to end). i've seen the answer about class memory layout in this question memory layout C++ objects

it says Nonstatic data members of a (non-union) class with the same access control (Clause 11) are allocated so that later members have higher addresses within a class object. but doesn't specify if they are sequential.

also is the paddings within a class among data members are also compilier dependent? If so, is specifying a certain padding size a good practice to fulfill this purpose?

and after all is it a good way to make a memory initialization like this? Is it good to reduce the times of the stream read call cause there may be so many data members within one class?

note: i can split pointers,strings,stls out and record their sizes, you can think this question only talks about base types.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...