RE: [Dev-C++] new is a wrapper around malloc so...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abhijit S. <mu...@gm...> - 2003-07-15 18:32:00
|
Hello, Ioannis and Daniel.
> I do not know what a Far pointer, but I do know that they exist. Can you
> tell us what does it mean?
Well, you must know that we have four basic segments (on the 8086) - the CS,
DS, SS and ES... by default, when a data pointer is defined, it is assumed
that the pointer resides in the data segment, and when a function pointer is
defined, that it resides in the code segment. However, when a pointer is
flagged as `far', it means that the segment is also stored explicitly along
with the offset. So, basically, far pointers allow you to access the whole
(and overwhelmingly huge) 1M of the 8086. Basically, far means residing in a
different segment, while near means residing in the same (the default)
segment.
Daniel, in response to your original question:
Assuming you code in Turbo-C++, you have three options:
1. Use a memory-model in which the required pointer's type is far by
default. If you need far data (the most common), use compact (in which the
data pointers are still near). If you need far code, use (umm, not sure,
really) large or huge (check the docs). You'll need to say something like
this:
char *foo = (char *)malloc(WHATEVER);
2. Use the farmalloc() function (in TC - in M$C, I've heard that it's named
halloc()). Corresponding frees should be done by farfree() (dunno about
M$C).
char far *foo = (char far *)farmalloc(WHATEVER);
// ...
farfree(foo);
3. The easiest - simply call `new'. AFAIK, you don't need to overload new:
char far *big_one = new char far[200];
// ^?
// Play around a bit with the syntax, I'm not sure that this works...
I remember doing something like this sometime back.
However, why do you need to use different segments at all? You should try
porting it to 32-bit protected-mode DOS (or even Windows console-mode), if
your application allows it. Sad as it is for me to say it, DOS is dead.
Anyway, here are a few links you might find interesting:
* http://www.delorie.com/djgpp
DJGPP - A DOS protected-mode C/++ compiler based on GCC
* http://sunsite.lanet.lv/ftp/mirror/x2ftp/msdos/programming/
The X2FTP - hordes of information on related topics.
HTH.
--
Abhijit Shylanath
Homepage: http://mudeth.tripod.com/
|