Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Saving a pointer to file

Saving a pointer to file

Scheduled Pinned Locked Moved C / C++ / MFC
help
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peter Molnar
    wrote on last edited by
    #1

    Hi, I have lots of pointers floating around in my application and it would be fun and also reduce the footprint of my app if I could save them temporarily to a file. Need help. Thanks B.

    C M P 3 Replies Last reply
    0
    • P Peter Molnar

      Hi, I have lots of pointers floating around in my application and it would be fun and also reduce the footprint of my app if I could save them temporarily to a file. Need help. Thanks B.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If you were to save the pointers, you would have a load of numbers on disk, and unless you didn't delete the memory they point to, they would be useless. If you didn't delete the memory, you'd just have the tedious job of making sure you did at some point and pulling them from the file. It sounds like a bad idea to me. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

      1 Reply Last reply
      0
      • P Peter Molnar

        Hi, I have lots of pointers floating around in my application and it would be fun and also reduce the footprint of my app if I could save them temporarily to a file. Need help. Thanks B.

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        Huh?:confused::confused: What do you mean ? that you have THAT many pointers that the memory is overflowing ? You want to save the pointers or the objects ? I think you want to have "auto" serializing objects, that will unload part of them on disk, and load it back when the pointer is accessed again ? is that what you want ? And you might save some memory, but the application would slow down! Max.

        1 Reply Last reply
        0
        • P Peter Molnar

          Hi, I have lots of pointers floating around in my application and it would be fun and also reduce the footprint of my app if I could save them temporarily to a file. Need help. Thanks B.

          P Offline
          P Offline
          Paul M Watt
          wrote on last edited by
          #4

          Generally you cannot save out pointers unless you were to create your own heap manager, and that is a task unto itself. What I would suggest to get the same effect that you are shooting for, is create a serializing function to store your objects to disk. All of the objects and strings that are shared through pointers should be stored in a table with an index or a handle ID. Then when you want to associate a the original pointer to the parent object, store the ID or index in the file instead. Then when you reload the file, you will have recreate the objects in the tables, but you can store the IDs or indices in the tables. And when you recreate the objects that use the pointers, you look up the pointers in the tables that you created. Good Luck


          Build a man a fire, and he will be warm for a day
          Light a man on fire, and he will be warm for the rest of his life!

          P 1 Reply Last reply
          0
          • P Paul M Watt

            Generally you cannot save out pointers unless you were to create your own heap manager, and that is a task unto itself. What I would suggest to get the same effect that you are shooting for, is create a serializing function to store your objects to disk. All of the objects and strings that are shared through pointers should be stored in a table with an index or a handle ID. Then when you want to associate a the original pointer to the parent object, store the ID or index in the file instead. Then when you reload the file, you will have recreate the objects in the tables, but you can store the IDs or indices in the tables. And when you recreate the objects that use the pointers, you look up the pointers in the tables that you created. Good Luck


            Build a man a fire, and he will be warm for a day
            Light a man on fire, and he will be warm for the rest of his life!

            P Offline
            P Offline
            Peter Molnar
            wrote on last edited by
            #5

            The pointers really point to some house made objects which are generated from a serial flow of data and then "consumed" by the app. The problem is that this app might be receiving data for a long time without consuming which, if not properly handled, might cause a memory blast. The solution seems to be the serialization/deserialization of objects into/from temp files. It is better having a slow ill app than having a quick dead. Thanks for the feedback. Bunburry

            M P 2 Replies Last reply
            0
            • P Peter Molnar

              The pointers really point to some house made objects which are generated from a serial flow of data and then "consumed" by the app. The problem is that this app might be receiving data for a long time without consuming which, if not properly handled, might cause a memory blast. The solution seems to be the serialization/deserialization of objects into/from temp files. It is better having a slow ill app than having a quick dead. Thanks for the feedback. Bunburry

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #6

              how come the data is not processed right when it's received ? don't answer, just thinking out loud... If your application is not speed dependant, I'd store the incoming data on disk right away, and only keep in memory the "file names", and when the data need to be processed, load it back from disk. The problem with that, is that if the amount of data "received" in the house objects is really small compared to the overhead of having it on file; you'll still have the same memory problem. Bunburry wrote: It is better having a slow ill app than having a quick dead. Well, it's better to have a healty running app than and slow and ill one! Max.

              1 Reply Last reply
              0
              • P Peter Molnar

                The pointers really point to some house made objects which are generated from a serial flow of data and then "consumed" by the app. The problem is that this app might be receiving data for a long time without consuming which, if not properly handled, might cause a memory blast. The solution seems to be the serialization/deserialization of objects into/from temp files. It is better having a slow ill app than having a quick dead. Thanks for the feedback. Bunburry

                P Offline
                P Offline
                Paul M Watt
                wrote on last edited by
                #7

                Bunburry wrote: The pointers really point to some house made objects which are generated from a serial flow of data and then "consumed" by the app. I would use memory mapped files! Store your data in a memory mapped file. That will allow you to access any part of the memory buffer as if it were a pointer (because it is loaded into memory), yet at the same time it is persisted to your harddrive. Therefore if you do not consume the data immediately it can be stored to disk. The only issue here is that you will need to manage the memory in the file in such a way that will allow you to flag the ranges of memory that have and have not yet been consumed. Bunburry wrote: It is better having a slow ill app than having a quick dead. Basically it is best to shoot for a healthy app. Once you get a basic design set forth that is healthy, you can always improve the speed later. The speed can come from eliminating processing that isnt necessary, or moving items to back ground threads and processes. Get your solution working first, then increase the speed later.


                Build a man a fire, and he will be warm for a day
                Light a man on fire, and he will be warm for the rest of his life!

                S 1 Reply Last reply
                0
                • P Paul M Watt

                  Bunburry wrote: The pointers really point to some house made objects which are generated from a serial flow of data and then "consumed" by the app. I would use memory mapped files! Store your data in a memory mapped file. That will allow you to access any part of the memory buffer as if it were a pointer (because it is loaded into memory), yet at the same time it is persisted to your harddrive. Therefore if you do not consume the data immediately it can be stored to disk. The only issue here is that you will need to manage the memory in the file in such a way that will allow you to flag the ranges of memory that have and have not yet been consumed. Bunburry wrote: It is better having a slow ill app than having a quick dead. Basically it is best to shoot for a healthy app. Once you get a basic design set forth that is healthy, you can always improve the speed later. The speed can come from eliminating processing that isnt necessary, or moving items to back ground threads and processes. Get your solution working first, then increase the speed later.


                  Build a man a fire, and he will be warm for a day
                  Light a man on fire, and he will be warm for the rest of his life!

                  S Offline
                  S Offline
                  S van Leent
                  wrote on last edited by
                  #8

                  Besides all thoses problems, it's not possible to have a garbage-collector working with it. LPCTSTR Dutch = TEXT("Double Dutch :-)");

                  P 1 Reply Last reply
                  0
                  • S S van Leent

                    Besides all thoses problems, it's not possible to have a garbage-collector working with it. LPCTSTR Dutch = TEXT("Double Dutch :-)");

                    P Offline
                    P Offline
                    Paul M Watt
                    wrote on last edited by
                    #9

                    You wont need a garbage collector, you will simply need a small class to manage the stream pointers for each of the data pieces. I have used a memory mapped file in a number of projects for interprocess communication where I managed data streams in both directions. In this particular instance, the data would be copied to the memory mapped file, and if the data should be stored to disk, the virtual memory pages will just need to be flushed to the disk and it is instantaneously saved.


                    Build a man a fire, and he will be warm for a day
                    Light a man on fire, and he will be warm for the rest of his life!

                    S 1 Reply Last reply
                    0
                    • P Paul M Watt

                      You wont need a garbage collector, you will simply need a small class to manage the stream pointers for each of the data pieces. I have used a memory mapped file in a number of projects for interprocess communication where I managed data streams in both directions. In this particular instance, the data would be copied to the memory mapped file, and if the data should be stored to disk, the virtual memory pages will just need to be flushed to the disk and it is instantaneously saved.


                      Build a man a fire, and he will be warm for a day
                      Light a man on fire, and he will be warm for the rest of his life!

                      S Offline
                      S Offline
                      S van Leent
                      wrote on last edited by
                      #10

                      Paul Watt wrote: You wont need a garbage collector, you will simply need a small class to manage the stream pointers for each of the data pieces. I have used a memory mapped file in a number of projects for interprocess communication where I managed data streams in both directions. I didn't make my point clear enough, I meant if you're using a Garbage Collector, the pointers move around, if you save the pointer to a file, you must explicitly lock the pointer, if not, the ponter is read but doesn't point to the right address. Sjoerd van Leent LPCTSTR Dutch = TEXT("Double Dutch :-)");

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups