Article View: rec.games.programmer
Article #130Re: Found problem (memory model question)
From: Peter SPHINX Cellik
Date: Wed, 22 Jul 1992 10:06
Date: Wed, 22 Jul 1992 10:06
40 lines
1967 bytes
1967 bytes
In article <1992Jul22.041040.28516@CS.ORST.EDU>, saidra@prism.CS.ORST.EDU (Raoul Said) writes:
|>
|> Ok, i have located the source of my problems after converting my code
|> from small to compact in Turbo C++. Maybe I am missing something simple here
|> but how come the following code produces two identical pointers? Am I doing
|> something I shouldn't be here? All I want is two pointers to the near heap
|> while in the compact memory model. When I run this code, my machine produces
|> two pointers that point to the same place in memory. Any ideas??
|>
|> void main()
|> {
|> char near *foo[2];
|>
|> foo[0] = (char near *)malloc(6);
|> foo[1] = (char near *)malloc(6);
|> }
|>
|> Thanks
The problem is that malloc in the compact memory model returns a far memory
pointer, not a near memory pointer. So you near pointer is only getting the
offset of the allocated buffer not the segment. Both offsets are probably
the same, thus you are getting the results you are.
solution:
You should use nalloc (or nearalloc, depending on the compiler, even _nalloc).
This will return a near pointer to a block of allocated memory in the near
data segment. You should then be able to use it with the near char pointers.
OK?
SPHINX
====================================================
=== Kill others only if you wish to be killed. ===
=== SPHINX ===
====================================================
Technical Details
Message-ID:
<1992Jul22.110639@axion.bt.co.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!axion!pcellikReferences:
<1992Jul22.041040.28516@CS.ORST.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!axion!pcellik From: pcellik@axion.bt.co.uk (Peter SPHINX Cellik) Newsgroups: rec.games.programmer Subject: Re: Found problem (memory model question) Message-ID: <1992Jul22.110639@axion.bt.co.uk> Date: 22 Jul 92 10:06:39 GMT References: <1992Jul22.041040.28516@CS.ORST.EDU> Sender: news@axion.bt.co.uk Reply-To: pcellik@axion.bt.co.uk (Peter SPHINX Cellik) Organization: British Telecom Research Labs Lines: 40