Thread View: rec.games.programmer
2 messages
2 total messages
Started by Raoul Said
Wed, 22 Jul 1992 04:10
Found problem (memory model question)
Author: Raoul Said
Date: Wed, 22 Jul 1992 04:10
Date: Wed, 22 Jul 1992 04:10
17 lines
998 bytes
998 bytes
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
Re: Found problem (memory model question)
Author: 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 ===
====================================================
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads