Storing data structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TDB

    Storing data structure

    Hello,

    I'm creating an application using C which requires the data structures
    like trees and graphs to be stored in files and retrieved later
    ( simply serialization of a data structure ) .

    Is there any libraries available in C for this purpose ?
  • santosh

    #2
    Re: Storing data structure

    TDB wrote:
    Hello,
    >
    I'm creating an application using C which requires the data structures
    like trees and graphs to be stored in files and retrieved later
    ( simply serialization of a data structure ) .
    >
    Is there any libraries available in C for this purpose ?
    The Standard library functions fread/fwrite should be sufficient
    primitives for this purpose.

    Comment

    • Richard Heathfield

      #3
      Re: Storing data structure

      santosh said:
      TDB wrote:
      >
      >Hello,
      >>
      >I'm creating an application using C which requires the data structures
      >like trees and graphs to be stored in files and retrieved later
      >( simply serialization of a data structure ) .
      >>
      > Is there any libraries available in C for this purpose ?
      >
      The Standard library functions fread/fwrite should be sufficient
      primitives for this purpose.
      You're right, but I don't think he was asking for primitives. He was asking
      for a library which "understand s" the serialisation of trees and graphs in
      a way that primitives don't. You can't just fwrite(root, sizeof *root, 1,
      fp) and expect the whole tree to be saved.

      --
      Richard Heathfield <http://www.cpax.org.uk >
      Email: -http://www. +rjh@
      Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
      "Usenet is a strange place" - dmr 29 July 1999

      Comment

      • jacob navia

        #4
        Re: Storing data structure

        TDB wrote:
        Hello,
        >
        I'm creating an application using C which requires the data structures
        like trees and graphs to be stored in files and retrieved later
        ( simply serialization of a data structure ) .
        >
        Is there any libraries available in C for this purpose ?
        You will have to do that yourself, i.e. you will have to transform
        the embedded pointers into pointers to other file structures.

        In a very general form, you should be able to translate pointers into
        indexes into a node array. When you read back the node array you
        transform again those indexes into real pointers.



        --
        jacob navia
        jacob at jacob point remcomp point fr
        logiciels/informatique

        Comment

        • Keith Thompson

          #5
          Re: Storing data structure

          santosh <santosh.k83@gm ail.comwrites:
          TDB wrote:
          >I'm creating an application using C which requires the data structures
          >like trees and graphs to be stored in files and retrieved later
          >( simply serialization of a data structure ) .
          >>
          > Is there any libraries available in C for this purpose ?
          >
          The Standard library functions fread/fwrite should be sufficient
          primitives for this purpose.
          Certainly, but I think that misses the OP's point. You have to
          flatten the data structure somehow, replacing any pointers with
          something more "static" (not in the C keyword sense), before you can
          fwrite anything.

          I don't know of any libraries to do this, but they probably exist.

          --
          Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
          Nokia
          "We must do something. This is something. Therefore, we must do this."
          -- Antony Jay and Jonathan Lynn, "Yes Minister"

          Comment

          • Willem

            #6
            Re: Storing data structure

            TDB wrote:
            ) Hello,
            )
            ) I'm creating an application using C which requires the data structures
            ) like trees and graphs to be stored in files and retrieved later
            ) ( simply serialization of a data structure ) .
            )
            ) Is there any libraries available in C for this purpose ?

            A library can only be expected to save a data structure in a file
            if it knows all the details of that data structure, and this is usually
            only the case if that library also provides those structures.
            So, IMO your best bet would be to look for tree- and graph-libraries.


            SaSW, Willem
            --
            Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
            #EOT

            Comment

            • Malcolm McLean

              #7
              Re: Storing data structure


              "TDB" <vnrbabu@gmail. comwrote in message news
              I'm creating an application using C which requires the data structures
              like trees and graphs to be stored in files and retrieved later
              ( simply serialization of a data structure ) .
              >
              Is there any libraries available in C for this purpose ?
              >
              Yes and no.
              One cannot store pointers in a file. Whilst there are general-purpose
              libraries that purport to be able to serialise structures, using a
              programmer-specified format string, these are so difficult to use that I
              think it is red herring to recommend them.
              However storing a tree is not too difficult. Simply write a bracket,
              recursively write the subtree, and then write a closing bracket.

              Loading is more tricky.
              If you look for the Newick tree loader on my website you might find what you
              are looking for. However it will only load trees, not graphs.

              --
              Free games and programming goodies.


              Comment

              • santosh

                #8
                Re: Storing data structure

                TDB wrote:
                Hello,
                >
                I'm creating an application using C which requires the data structures
                like trees and graphs to be stored in files and retrieved later
                ( simply serialization of a data structure ) .
                >
                Is there any libraries available in C for this purpose ?
                One link I found through Google is:

                <http://tpl.sourceforge .net/>

                HTH

                Comment

                • Friedrich Dominicus

                  #9
                  Re: Storing data structure

                  TDB <vnrbabu@gmail. comwrites:
                  Hello,
                  >
                  I'm creating an application using C which requires the data structures
                  like trees and graphs to be stored in files and retrieved later
                  ( simply serialization of a data structure ) .
                  >
                  Is there any libraries available in C for this purpose ?
                  As others have pointed out without some work on your side this won't
                  work. Howerver you may check the berkeley DB stuff which offers quite
                  a bunch for "persitence in C"



                  Regards
                  Friedrich


                  --
                  Please remove just-for-news- to reply via e-mail.

                  Comment

                  • CBFalconer

                    #10
                    Re: Storing data structure

                    Keith Thompson wrote:
                    santosh <santosh.k83@gm ail.comwrites:
                    >TDB wrote:
                    >>
                    >>I'm creating an application using C which requires the data
                    >>structures like trees and graphs to be stored in files and
                    >>retrieved later (simply serialization of a data structure).
                    >>>
                    >>Is there any libraries available in C for this purpose ?
                    >>
                    >The Standard library functions fread/fwrite should be
                    >sufficient primitives for this purpose.
                    >
                    Certainly, but I think that misses the OP's point. You have to
                    flatten the data structure somehow, replacing any pointers with
                    something more "static" (not in the C keyword sense), before you
                    can fwrite anything.
                    >
                    I don't know of any libraries to do this, but they probably
                    exist.
                    Highly doubtful. Any such library would have to understand the
                    entire organization of the trees and graphs.

                    --
                    [mail]: Chuck F (cbfalconer at maineline dot net)
                    [page]: <http://cbfalconer.home .att.net>
                    Try the download section.



                    --
                    Posted via a free Usenet account from http://www.teranews.com

                    Comment

                    Working...