flat assembler
Message board for the users of flat assembler.
Index
> Main > serializing pointers |
Author |
|
vivik 27 Mar 2017, 07:26
Imagine that you need to save in a file some struct, which points to another struct. How would you do that?
|
|||
27 Mar 2017, 07:26 |
|
redsock 27 Mar 2017, 07:39
I have devoted a considerable amount of time in the past to this/similar problems. See: https://2ton.com.au/library_as_html/mappedheap.inc.html by way of example.
Instead of pointers, all "memory" (e.g. file space) is referred to by offset instead of by physical memory location, solving such a use case. I have gone on to create many derivative structures from this same underlying idea: https://2ton.com.au/library_as_html/mtree.inc.html Hope this helps stir some thought |
|||
27 Mar 2017, 07:39 |
|
Tomasz Grysztar 27 Mar 2017, 07:46
The fasm's symbolic information file format is another example of approaching a similar problem. It contains "dumps" of many structures that are used by fasm internally at run-time, and when preparing these structures to be saved in file the addresses in memory need to be changed into relative offsets within the sections of file. Each part of file is prepared within memory as a contiguous block and all pointers inside various structures are converted into relative offsets relative to the start of a given block.
|
|||
27 Mar 2017, 07:46 |
|
revolution 27 Mar 2017, 09:44
There is no need to move the blocks around within memory. Just assign the offsets in ascending order when serialising.
|
|||
27 Mar 2017, 09:44 |
|
Tomasz Grysztar 27 Mar 2017, 09:50
If your blocks are all over the place, you can create some data structure to store the pairings of memory addresses (values of pointers) with offsets in file. If memory usage is not a concern, a binary trie might be a recommendable choice. It would have to be done in two passes - first one to reserve offsets in file for every structure that you need to save (and store these offsets as values for memory address keys in the aforementioned data structure), then in the second pass replace all the pointers within the structures with the offsets reserved earlier and then save structures at the corresponding positions in file.
|
|||
27 Mar 2017, 09:50 |
|
revolution 27 Mar 2017, 09:55
It can also be done in a single pass with a recursive function. The storage requirements would also be smaller.
|
|||
27 Mar 2017, 09:55 |
|
Tomasz Grysztar 27 Mar 2017, 09:57
revolution wrote: It can also be done in a single pass with a recursive function. The storage requirements would also be smaller. |
|||
27 Mar 2017, 09:57 |
|
revolution 27 Mar 2017, 10:24
Fair enough
If you know that your structures don't have back-references or circular-references then ... it can also be done in a single pass with a recursive function. |
|||
27 Mar 2017, 10:24 |
|
vivik 27 Mar 2017, 10:27
revolution wrote: There is no need to move the blocks around within memory. Just assign the offsets in ascending order when serialising. I planned to use memory mapped files, and writing into them is moving memory into them. This is why I said that I need to move all memory blocks into one. Probably should have said "copy" instead. Awesome replies, thank you! |
|||
27 Mar 2017, 10:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.