By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,092 Members | 1,597 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,092 IT Pros & Developers. It's quick & easy.

flatten class and flatten struct

P: n/a
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;
}

Sep 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
we*****@yahoo.com wrote:
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-lit...alization.html

and compare Boost's serialization library:

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

Cheers! --M

Sep 27 '06 #2

P: n/a
mlimber <ml*****@gmail.comwrote:
>we*****@yahoo.com wrote:
>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?
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
Sep 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.