Mail Archives: djgpp/1997/05/29/23:05:14
IEX & SAMPLE wrote:
>
> Hello, I'm new to DJGPP and protected-mode programming, I was
> wondering how do I use protected mode? Do programs made w/ DJGPP
> automatically go into protected mode when they are run??
Yes. And you don't need to worry about it at all unless you start
performing hardware-dependent operations, such as graphics and interrupt
handling. In that case, the techniques you learned for real-mode
compilers will NOT work, and either won't compile or will crash your
programs.
Please get and read the DJGPP Frequently Asked Questions list
(v2/faq210b.zip), which explains a great deal of this stuff and gives
you pointers and examples of things to watch out for in protected mode.
But just for kicks, try the following program:
/* lotsamem.c */
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
char *p;
int megs;
printf( "How many megabytes would you like to allocate (1-256)? " );
if ( scanf( "%d", &megs ) < 1 || megs < 1 || megs > 256 )
printf( "That's not what I asked for, dufus.\n" );
else
{
p = malloc( megs * 1048576 );
if ( p != NULL )
{
printf( "Wow! You just allocated %d megabytes!\n", megs );
free( p );
}
else
printf( "Whoops! You don't have enough memory available.
Sorry.\n" );
}
return 0;
}
Compile it by typing "gcc -o lotsamem.exe lotsamem.c".
Run it by typing "lotsamem".
Enjoy. ;)
Note: depending on what DPMI host you run under (cwsdpmi, Windows,
Linux, OS/2, QDPMI, etc.), you may have varying amounts of free memory
and may not be able to allocate it all in one chunk. But that's an
advanced topic.
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com |
| "Starting flamewars since 1993" | http://www.cs.com/fighteer |
| *** NOTICE *** This .signature is generated randomly. |
| If you don't like it, sue my computer. |
---------------------------------------------------------------------
- Raw text -