Saving a pointer to file
-
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.
-
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.
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
-
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.
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.
-
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.
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! -
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!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
-
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
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.
-
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
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! -
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!Besides all thoses problems, it's not possible to have a garbage-collector working with it. LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Besides all thoses problems, it's not possible to have a garbage-collector working with it. LPCTSTR Dutch = TEXT("Double Dutch :-)");
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! -
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!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 :-)");