flatten class and flatten struct

W

wenmang

Hi,
As part of simple serialization, I like to determine which is the right
way to do:
flatten a class containing flat C-structs with some member functions or
just plain C-structs. We need to store those data as context in shared
memory. I just want to know what is pro and cons for this idea:
class Context
{
public:
memFun1();
memFun2();
Data1 data1;
Data2 data2;
}
OR
struct Context
{
Data1 data1;
Data2 data2;
}
 
M

mlimber

Hi,
As part of simple serialization, I like to determine which is the right
way to do:
flatten a class containing flat C-structs with some member functions or
just plain C-structs. We need to store those data as context in shared
memory. I just want to know what is pro and cons for this idea:
class Context
{
public:
memFun1();
memFun2();
Data1 data1;
Data2 data2;
}
OR
struct Context
{
Data1 data1;
Data2 data2;
}

Huh? You can serialize a class/struct with private/protected/public
data and with/without member functions just as well as you can
serialize a C-style, POD struct. What's the question again? See these
FAQs on serialization:

http://www.parashift.com/c++-faq-lite/serialization.html

and compare Boost's serialization library:

http://boost.org/libs/serialization/doc/index.html

Cheers! --M
 
S

Steve Pope

mlimber said:
(e-mail address removed) wrote:
Huh? You can serialize a class/struct with private/protected/public
data and with/without member functions just as well as you can
serialize a C-style, POD struct. What's the question again?

I think the question may have been: given the first class, should
one create the second struct before serializing the data out to
wherever it's going.

If so, I think the answer is no -- why create a new struct, when
you can just serialize the data in the existing class. You do
not need to serialize the member functions as they already redundantly
exist in the class declarations at each end of the serial connection.

(If that's not the question, then ignore what I wrote above.)

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top