I have a very complex data structure with pointers to various parts of the memory. It takes a while to build and I would like to save the "memory" used by that structure to the disk. Then, when the program is launched again, it would just memory map the file and I could use it. Is there any way to do this ?
saving data structure c++ to disk
2.9k views Asked by madreblu At
3
There are 3 answers
0
Jan Herrmann
On
You could start with Boost.Interprocess and use memory maped files. Your data structure will look a litle differnt (pointers are smart pointers, references forbidden, no virtual functions). But it should be manageable. At least all types you use needs to be constructable in shared memory. Some are (Boost.Container) and some are not (Boost.Any, Boost.Variant).
Related Questions in C++
- How to immediately apply DISPLAYCONFIG_SCALING display scaling mode with SetDisplayConfig and DISPLAYCONFIG_PATH_TARGET_INFO
- Why can't I use templates members in its specialization?
- How to fix "Access violation executing location" when using GLFW and GLAD
- Dynamic array of structures in C++/ cannot fill a dynamic array of doubles in structure from dynamic array of structures
- How do I apply the interface concept with the base-class in design?
- File refuses to compile std::erase() even if using -std=g++23
- How can I do a successful map when the number of elements to be mapped is not consistent in Thrust C++
- Can std::bit_cast be applied to an empty object?
- Unexpected inter-thread happens-before relationships from relaxed memory ordering
- How i can move element of dynamic vector in argument of function push_back for dynamic vector
- Brick Breaker Ball Bounce
- Thread-safe lock-free min where both operands can change c++
- Watchdog Timer Reset on ESP32 using Webservers
- How to solve compiler error: no matching function for call to 'dmhFS::dmhFS()' in my case?
- Conda CMAKE CXX Compiler error while compiling Pytorch
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in DATA-STRUCTURES
- Why is the runtime for this O(n)?
- Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique
- What is the problem in my "sumAtBis" code?
- Asking code suggestions about data structure and algorithm
- What would be the most efficient way to store multiple sets of fixed arrays (std::vector)?
- About Suffix Trees features
- Getting wrong answer in Binary Search solution
- Are there techniques to mathematically compute the amount of searching in greedy graph searching?
- AVL tree Nth largest operation - How to have all my tests pass? JAVA
- Why does the map size change?
- Complexity in Union of disjointed sets with lists
- Hash collisions in Golang map resolving
- C++ ordered map optimized with index access
- How to sort this list of strings along with the strings and output the result as expected?
- Why deleting an element in a linkedlist costs O(1)
Related Questions in SAVE
- Flutter: How to add items and save it in local storage?
- Can be their an extension to save pages in as offline in the browser itself?
- Excel VBA macro works flawlessly on my computer, but has different errors on different machines?
- Cannot save a Custom Variational Autoencoder Model built in Keras with tensor flow
- String Type Value Member and Display Member in VB.NET Combobox with manually filled data
- VBA Word changing command button properties prevents closing without save prompt
- How to save plots one at a time from momentuHMM fit object?
- what is the expected behavior if you try to save an openpyxl workbook on a file that is already open?
- Nextjs: How to save simple data even in a way that are not lost when navigation between routes?
- Excel VBA unable to save file on a network drive
- Android Studio Error : Class declares multiple JSON fields named 'mLifecycleRegistry';
- How to save a file in Files iOS system app in iOS 17 Swift
- Saving a base64 code into a folder gives me a failed image and cannot open it with PHP
- In Oracle Cloud Infrastructure, how to upload a csv file generated in a notebook directly into a bucket?
- Tensorflow - Save & Load custom model in Keras v3 format
Related Questions in STATE-SAVING
- Error when restoring view after rolling update
- React useEffect cleanup function to save state to a database without running into closure probelms
- How to save the state of PowerShell in Windows 10 as to continue with it later?
- How do I save the step where the user left off in the wizard using Wicked gem?
- How can I persist or save states in reactjs?
- Need help making Swift Cookie Clicker Game Automatically Save
- How to save game progress for different devices?
- ClassCastException: <![CDATA[java.util.HashMap cannot be cast to [[Ljava.lang.Object;]]>
- Angularjs dataTable stateSave not woking on change routes
- this.setState not functioning properly
- JSF Servlet Exception: No view save state when application session jumps between servers
- How can I save and load textbox values, checkbox states, dropdown menu selections, etc., into a .txt file?
- React.js, correct way to iterate inside DOM
- Saving Cube like in Minecraft game
- Composite component recursion
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
It can be done, yes, but you need to be aware of how the structure is actually stored in memory, and how that changes on various platforms (alignment, packing, byte-ordering, primitive type sizes, etc.). Additionally, it would be prudent to change your "pointers to various parts" into "offsets to various parts" since actual memory locations will change between process uses.
example, writing an object like this to disk should be fairly portable:
but one like this would be very problematic: