Article View: comp.os.ms-windows.programmer.misc
Article #1754Segmented Memory Woes and Portability
From: Andrew Joseph Kompanek
Date: Mon, 14 Dec 1992 23:42
Date: Mon, 14 Dec 1992 23:42
48 lines
2938 bytes
2938 bytes
I recently started porting some data structure libraries I wrote on Unix to the PC under Windows 3.1. I'm using Borland C++ 3.1. I naively assumed that all of the segmented memory issues would be more or less transparent to me and that the compiler would take care of pointer conversions, alignment problems, etc. I figured if I compiled my code with the Compact option, my pointer declarations would be interpreted as far pointers and that I could address within a 1 Mb address space without changing a bit of my code. This doesn't _seem_ to work, though I just started and still don't know very much about the 80x86. So, if this doesn't work, what is the best way to write code portable to 80x86 architectures -- both under DOS and in Windows programs and DLLs? I realize with a little research and a lot of #ifdefs I could write some portable code but it would be extremely useful to be able to hide the PC-specific code from the programmer using malloc(). Has somebody put some sort of library together? Alternatively, is it possible to simply call GlobalAlloc() or whatever the function is to allocate memory from Windows global heap, convert the handle to a far/huge pointer (the pointer declarations somehow declared this way implicitly), lock the memory then when you're done with it, convert the pointer back to a handle, unlock and free it? This seems like sensible behavior -- assuming that this doesn't force Windows to keep in memory stuff that should it should be able to move and swap in/out. As a programmer, it doesn't seem like I should have to deal with the quirks of the processor I'm running on... My understanding of the 386/486 is that it has better support for virtual memory management and that its virtual 32-bit pointers look like contiguous, unmoving addressable memory. Is there a way to do this in Borland C++ 3.1? Judging from some of the other posts about memory management, it seems that a lot of people might benefit from discussing some of the stuff I've brought up. If this is FAQ material, I'm sorry for clogging network bandwith with this message. Drew ------------------------------------------------------------------------------ Andrew Kompanek e-mail: drew@chimera.hgen.pitt.edu, Department of Human Genetics ak10@andrew.cmu.edu, University of Pittsburgh kompanek@cs.cmu.edu ------------------------------------------------------------------------------
Technical Details
Message-ID:
<wf=Fjj_00WB8QZoUYr@andrew.cmu.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!ak10+Show Full Headers
Complete Article Headers
Organization: Carnegie Mellon, Pittsburgh, PA Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!ak10+ Newsgroups: comp.os.ms-windows.programmer.misc Message-ID: <wf=Fjj_00WB8QZoUYr@andrew.cmu.edu> Date: Mon, 14 Dec 1992 18:42:39 -0500 From: Andrew Joseph Kompanek <ak10+@andrew.cmu.edu> Subject: Segmented Memory Woes and Portability Lines: 48