468,512 Members | 1,426 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

flatten class and flatten struct

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
2 3176
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
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.

Similar topics

23 posts views Thread by Francis Avila | last post: by
18 posts views Thread by Ville Vainio | last post: by
4 posts views Thread by johns1111 | last post: by
1 post views Thread by farooq.omar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.