Date: Wed, 11 Nov 1998 12:20:06 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: Jonathan Villani cc: djgpp AT delorie DOT com Subject: Re: Question regarding the use of __djgpp_nearptr_enable() In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com On Tue, 10 Nov 1998, Jonathan Villani wrote: > I have seen tutorials on the web for programming the DMA but all them use > the __djgpp_nearptr_enable function. I would guess that this is due to three main reasons: 1) Near pointers make the coding somewhat easier, especially if the programmer is used to access absolute addresses with normal C pointers and data structures. 2) Near pointers make it easier to convert real-mode programs to DJGPP without understanding too much how does protected mode work. 3) People tend to think (incorrectly, IMHO) that near pointers make your program a whole lot faster. > I don't want to use that because it disable the memory protection. You are right. > Here's some code from the tutorials: > -------------------------------------------------- > > void *MK_FP(DWORD seg, DWORD ofs) > { > if (!(_crt0_startup_flags & _CRT0_FLAG_NEARPTR)) > if > (!__djgpp_nearptr_enable()) ------------------------------------------------ > > Oh no ! no memory protection! > return (void*)0; > return (void *) (seg*16+ofs+__djgpp_conventional_base); > } This was taken directly from the FAQ, where this code is supposed to help those who have a lot of real-mode code using the MK_FP macro. I never meant for this to proliferate, I just wanted to help those who need a one-time quick-and-dirty hack to make some legacy program work with minimal effort. Note that the __djgpp_nearptr_enable/disable functions call a DPMI service, which will tremendously slow down your program if you call MK_FP in some inner loop or in a time-critical section of your code. > memset((BYTE *)MK_FP(SegInfo.rm_segment,0),0,BUFFSIZE); ----------> Set > buffer to 0 using nearpointer! `dosmemput' would make the same job with the same speed, but without compromising memory protection. > (A) __djgpp_nearptr_enable(); ------------------> Does this line will > slow down my real time app.?? It does, a lot! > /* COPY using DOS memory using Nearpointers */ > memset(...[DMAbuffer -> in DOS memory]) > .... > (B) __djgpp_nearptr_disable(); ------------------> Does this line will > slow down my real time app.?? Yes, it will be very slow. Just use `dosmemput' instead of near pointers, and you will get a program that's not only safer, but also much faster.