delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/11/16:35:51

Date: Tue, 11 Mar 1997 23:17:24 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
cc: djgpp AT delorie DOT com
Subject: Re: 'Smart' far pointers in C++
In-Reply-To: <1vA+sDATpBJzEwIJ@talula.demon.co.uk>
Message-ID: <Pine.SUN.3.91.970311231707.2704B-100000@is>
MIME-Version: 1.0

On Mon, 10 Mar 1997, Shawn Hargreaves wrote:

> It just occured to me that in C++ it would be possible to write a wrapper
> class for the routines in <sys/farptr.h>, that makes them behave very much
> like normal C pointers. So I tried it, and it does indeed work!

Anthony Appleyard has posted something along these same lines a few
months ago.  (Great minds think alike ;-)

> Example of drawing random pixels to the VGA screen:
> 
>    farptrb ptr(0xA0000);
> 
>    _farsetsel(_dos_ds);
> 
>    for (int y=0; y<200; y++)
>       for (int x=0; x<320; x++)
>          ptr[x+y*320] = rand();

Why not make the size of the memory region you want to access be a
parameter of the class as well?  That way, you could have the
constructor allocate a selector for the appropriate memory region
using either the `__dpmi_get_descriptor' or
`__dpmi_segment_to_descriptor' library functions (see section 18.4 of
the FAQ for details) and avoid the need to require the user to call
`_farsetsel'.  I think this requirement is not-so-C++ way of doing
things, and that users will forget it and crash.

Also, I would like to point out that using `_dos_ds' is a bit dangerous
in the current DJGPP setup and should be kept at bare minimum, because
that selector has a 4GB limit, which effectively disables memory
protection when you use it.  Anyone who cares about scrogging his
system should IMHO patch the startup code in his/her library to change
the limit to 1MB.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019