home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / misc / 4241 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  3.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: <711@lax.lax.pe-nelson.com>
  6. Date: 15 Dec 92 17:22:19 GMT
  7. References: <wf=Fjj_00WB8QZoUYr@andrew.cmu.edu>
  8. Sender: news@lax.pe-nelson.com
  9. Organization: PE-Nelson
  10. Lines: 69
  11.  
  12. In article <wf=Fjj_00WB8QZoUYr@andrew.cmu.edu>, ak10+@andrew.cmu.edu (Andrew Joseph Kompanek) writes:
  13. |> 
  14. |> I recently started porting some data structure libraries I wrote on Unix
  15. |> to the PC under Windows 3.1.  I'm using Borland C++ 3.1.
  16. |> 
  17. |> I naively assumed that all of the segmented memory issues would be
  18. |> more or less transparent to me and that the compiler would take care
  19. |> of pointer conversions, alignment problems, etc. 
  20.  
  21. Hahahahahahahahaha -- sorry, I'm not trying to be rude :-)
  22.  
  23.  
  24. |>                                                        I figured if I
  25. |> compiled my code with the Compact option, my pointer declarations
  26. |> would be interpreted as far pointers and that I could address within a
  27. |> 1 Mb address space without changing a bit of my code.  This doesn't
  28. |> _seem_ to work, though I just started and still don't know very much
  29. |> about the 80x86.
  30. |> 
  31. |> So, if this doesn't work, what is the best way to write code portable to
  32. |> 80x86 architectures -- both under DOS and in Windows programs and DLLs?
  33.  
  34. Use large model -- that's what we use and have had no problems.  It's
  35. anticipated that large model will be the easiest to port to Windows/NT.
  36.  
  37. But realize -- until you use WIN32s or Windows/NT you are not in a 32-bit
  38. environment, you are in a 16:16 segmented environment and a single selector
  39. won't allow you to address over 64 Kb of memory.
  40.  
  41.  
  42. |> Alternatively, is it possible to simply call GlobalAlloc() or whatever
  43. |> the function is to allocate memory from Windows global heap, convert the handle
  44. |> to a far/huge pointer (the pointer declarations somehow declared this way
  45. |> implicitly), lock the memory then when you're done with it, convert the
  46. |> pointer back to a handle, unlock and free it?  This seems like sensible
  47. |> behavior -- assuming that this doesn't force Windows to keep in memory
  48. |> stuff that should it should be able to move and swap in/out.
  49.  
  50. Certainly it's possible to do that though I've tried to stay away from huge
  51. pointers because; 1) of the overhead in their use, 2) they chew up selectors, 
  52. and 3) the "conventional" normalized huge pointers can't be used in
  53. protected mode Windows programming.
  54.  
  55.  
  56. |> 
  57. |> As a programmer, it doesn't seem like I should have to deal with the
  58. |> quirks of the processor I'm running on...
  59.  
  60. Sorry, but that's a little idealistic.  I'd hardly call the fact that
  61. MSDOS and Windows currently operate in a 16:16 segmented mode a quirk, it's
  62. a fact of life.  Start using WIN32s and/or Windows/NT where you have 16:32
  63. segments that more closely mimic the address space you're used to.
  64.  
  65.  
  66. |> 
  67. |> My understanding of the 386/486 is that it has better support for virtual
  68. |> memory management and that its virtual 32-bit pointers look like contiguous,
  69. |> unmoving addressable memory.  Is there a way to do this in Borland C++ 3.1?
  70.  
  71. Not currently -- when Borland provides support for 32-bit Windows then
  72. you'll get this.
  73.  
  74.  
  75.  
  76. ----------------------------------------------------------------------------
  77. Tom Brown               |  "She turned me into a newt...
  78. PE Nelson Systems       |                                  ... I got better"
  79. twbrown@pe-nelson.com   |                    Monty Python and the Holy Grail
  80. ----------------------------------------------------------------------------
  81.