home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / wizards / 5302 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  4.2 KB

  1. Xref: sparky comp.unix.wizards:5302 comp.unix.programmer:5758 comp.unix.questions:14872
  2. Newsgroups: comp.unix.wizards,comp.unix.programmer,comp.unix.questions
  3. Path: sparky!uunet!spool.mu.edu!yale.edu!yale!gumby!destroyer!cs.ubc.ca!uw-beaver!news.u.washington.edu!carson.u.washington.edu!donn
  4. From: donn@carson.u.washington.edu (Donn Cave)
  5. Subject: Re: Portability issues in using a memory dump
  6. Message-ID: <1992Dec22.020320.18609@u.washington.edu>
  7. Sender: news@u.washington.edu (USENET News System)
  8. Organization: University of Washington
  9. References: <1992Dec17.222402.18347@sj.ate.slb.com> <1992Dec21.165835.17205@thunder.mcrcim.mcgill.edu>
  10. Date: Tue, 22 Dec 1992 02:03:20 GMT
  11. Lines: 70
  12.  
  13. mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:
  14. |In article <1992Dec17.222402.18347@sj.ate.slb.com>, bharat@sj.ate.slb.com (Bharat Venkatasubramanian) writes:
  15.  
  16. |> I have a wierd problem.  I would like to dump the contents of a chunk
  17. |> of contiguous memory locations.   The contents represent some complex
  18. |> graph structure which once built is constant over different
  19. |> invocations of the program.
  20.  
  21. |> Instead of traversing the graph and dumping its contents, I would
  22. |> like to dump the contents of this contiguous memory.  Subsequent
  23. |> invocations of this program could then use mmap() system call to map
  24. |> the information in this file to the address used when the file was
  25. |> first created.
  26.  
  27. | It's a bit ugly, but it should be workable on most systems.  Sendmail
  28. | does something similar with its frozen config files.
  29.  
  30. Beauty is in the eye of the beholder, I guess.  I've done it, with a tree
  31. structure, and I thought it was rather cute.
  32.  
  33. |> The program has static behavior until the creation of this graph and
  34. |> so on the same machine I will definitely be able to guarantee the
  35. |> availability of that address space.
  36.  
  37. | Are you sure?  Part of that space is probably already occupied by
  38. | data/bss.
  39. Part of what space?  He should dump the entire address space, for what?
  40.  
  41. | Unless you are specifically allocating a block of memory for this
  42. | purpose, and want to save and restore only that block.  You still may
  43. | be better off with read than mmap, if for no other reason than some
  44. | systems don't have mmap.
  45.  
  46. Specifically allocating a block of memory is likely to be a more
  47. productive strategy, although you do have to ensure that everything that
  48. matters gets allocated from that block.  As for mmap(), not only do some
  49. systems not have it, but it doesn't seem to behave identically between
  50. systems that do.  However, I would suggest starting with mmap(), since
  51. that puts some extra constraints on the problem (e.g., page alignment),
  52. and then add read() (and write()) alternatives if it proves necessary.
  53. It's not greatly different, mmap = read, close = write, and those nice
  54. #ifdefs make your code more readable.  The mmap() incompatibilities I
  55. alluded to aren't severe; no use asking me what they are, as I have
  56. forgotten everything.
  57.  
  58. |> One of my concerns is will the address space be different on
  59. |> different Operating Systems??
  60.  
  61. | Yes.  The difference is usually fairly minor; most UNIXish systems just
  62. | give you text/data/stack at runtime, so if you dump out the data
  63. | segment you should be OK, even though the data segment may begin at a
  64. | different address and be a different size from system to system.  If
  65. | you encounter a system that doesn't fit this model, you may have to
  66. | abandon this technique.  (On SunOS 4.x, for example, you will likely
  67. | have to link -Bstatic if you want to dump the whole data segment,
  68. | because otherwise pieces of the conceptual data segment are up at
  69. | random addresses thanks to shared object files being brought in at
  70. | run-time.)
  71.  
  72. On the other hand, if you don't aspire to dump the whole data segment, but
  73. rather have a discrete chunk of data that's supposed to reside at a particular
  74. address, and you have allocated the memory required for that, then the
  75. address space is exactly the same, right?  To me, this seems like the way
  76. to go.  Do consider labelling the data, inside the file, with some information
  77. about the starting address and extent of your data - at least then when you
  78. recompile the program and change addresses, your program can tell you that
  79. you have obsoleted your old data.
  80.  
  81.     Donn Cave, University Computing Services, University of Washington
  82.     donn@cac.washington.edu
  83.