flatten class and flatten struct

Discussion in 'C++' started by wenmang@yahoo.com, Sep 27, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. mlimber Guest

    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-lite/serialization.html

    and compare Boost's serialization library:

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

    Cheers! --M
     
    mlimber, Sep 27, 2006
    #2
    1. Advertising

  3. Steve Pope Guest

    mlimber <> wrote:

    > 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
     
    Steve Pope, Sep 27, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Fogelklou
    Replies:
    36
    Views:
    1,405
    Chris Fogelklou
    Apr 20, 2004
  2. Heiko Wundram

    ANN: yawPyCrypto 0.1 and Flatten 0.2

    Heiko Wundram, Aug 11, 2003, in forum: Python
    Replies:
    0
    Views:
    292
    Heiko Wundram
    Aug 11, 2003
  3. Francis Avila
    Replies:
    0
    Views:
    478
    Francis Avila
    Nov 2, 2003
  4. Replies:
    2
    Views:
    750
    David Harmon
    Sep 20, 2006
  5. Tzury Bar Yochay
    Replies:
    4
    Views:
    582
    John Machin
    Sep 21, 2008
Loading...

Share This Page