home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / misc / 4260 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  4.6 KB

  1. Path: sparky!uunet!lax.pe-nelson.com!lax!twbrown
  2. From: twbrown@PE-Nelson.COM (Tom W. Brown)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: Segmented Memory Woes and Portability
  5. Message-ID: <714@lax.lax.pe-nelson.com>
  6. Date: 16 Dec 92 01:03:42 GMT
  7. References: <wf=Fjj_00WB8QZoUYr@andrew.cmu.edu> <711@lax.lax.pe-nelson.com> <1992Dec15.174802.15272@emr1.emr.ca>
  8. Sender: news@lax.pe-nelson.com
  9. Organization: PE-Nelson
  10. Lines: 84
  11.  
  12. In article <1992Dec15.174802.15272@emr1.emr.ca>, jagrant@emr1.emr.ca (John Grant) writes:
  13. |> In article <711@lax.lax.pe-nelson.com> twbrown@PE-Nelson.COM (Tom W. Brown) writes:
  14. |> >In article <wf=Fjj_00WB8QZoUYr@andrew.cmu.edu>, ak10+@andrew.cmu.edu (Andrew Joseph Kompanek) writes:
  15. |> [...stuff deleted about segmented memory confusion...]
  16. |> 
  17. |> >Certainly it's possible to do that though I've tried to stay away from huge
  18. |> >pointers because; 1) of the overhead in their use,
  19. |>     Yes, but it's really not that bad is it?
  20.  
  21. Dunno, it depends on how much pointer arithmetic you're doing on the huge
  22. pointers. 
  23.  
  24. But a statement like "p++" becomes either a function call or a block of inline
  25. code that increments the offset, checks to see whether the segment (selector)
  26. should be modified, and possibly then resets the offset back within some
  27. range.  Sounds like a lot of overhead to me.
  28.  
  29. |> 
  30. |>  2) they chew up selectors, 
  31. |>     Tom, could you please explain this - I don't understand.
  32.  
  33. This is a protected mode consideration only.  To allocate a huge block of
  34. memory and be able to access it you would need to reserve some number of
  35. segment selectors from the descriptor table.  Since we still only have 16
  36. bit offsets you need to reserve a segment selector for each 64 Kb block in
  37. your huge array, and that assumes that the huge pointer implementation
  38. makes maximum use of the offset portion of the pointer which may not be
  39. true.
  40.  
  41. There are only ~8192 total selectors available in enhanced mode, ~4096
  42. selectors available in standard mode.  Every code segment, data segment,
  43. resource, etc. takes up a selector (i.e. every separate line item that you
  44. see in HeapWalker).
  45.  
  46. We ran up hard against this selector limit in our application, building
  47. our C++ data structures where a list of objects, each containing lists of
  48. smaller objects, and so on caused enough global allocation to use up the
  49. descriptor table entries.  We switched to a 3rd party memory manager
  50. (OptiMem from MicroQuill) which has a much better subsegment allocator than
  51. the Borland runtime.
  52.  
  53. I'm probably over reacting to the extra use of selectors because of our
  54. recent problems with this limit -- a single "huge" array probably won't
  55. get you into trouble.  A 1 Mb array would need 16 segment selectors to
  56. fully access it, probably not a big deal (but then, who knows?)
  57.  
  58.  
  59. |> 
  60. |> >and 3) the "conventional" normalized huge pointers can't be used in
  61. |> >protected mode Windows programming.
  62. |>     I don't understand this either.  Are there 2 kinds of huge
  63. |>     pointers? - "conventional" & "non-conventional"?  And why
  64. |>     can't they be used in protected mode?
  65.  
  66. Well, normalized huge pointers are for real mode and they are probably what
  67. most DOS programmer's are used to.  A normalized huge pointer always ensures
  68. that the offset portion is between 0x0000 and 0x000F inclusive.  Once the
  69. offset would increment to 0x0010, the segment is incremented instead and the
  70. offset is reset to zero.  This, of course, relies on the real mode property
  71. that the segment corresponds to part of the physical address.
  72.  
  73. The reason this is done is to guarantee that two different pointer bit
  74. patterns can't point to the same memory which in turn allows pointer
  75. comparisons to be done more efficiently (compare the segments and only if
  76. equal do you need to compare the offsets).
  77.  
  78. In protected mode you can't do this, simply incrementing a segment selector
  79. will almost certainly generate a GPF.  You would need to reserve a selector
  80. for every 16 bytes of your array and guarantee that they were consecutive
  81. (perhaps with an offset) in order for this type of normalization to work.
  82.  
  83. --------------------------------------------------------------------------
  84.  
  85. Anyway, in a C++ environment it's easy to create an class (template) that
  86. looks and feels like an array, allows you to access more than 64K of data,
  87. and doesn't need to use huge pointers.  This is definitely the way to go!
  88.  
  89.  
  90. ----------------------------------------------------------------------------
  91. Tom Brown               |  "She turned me into a newt...
  92. PE Nelson Systems       |                                  ... I got better"
  93. twbrown@pe-nelson.com   |                    Monty Python and the Holy Grail
  94. ----------------------------------------------------------------------------
  95.  
  96.