home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / tech / pcbsrcs2 / alloc2.c < prev    next >
Text File  |  1991-02-07  |  854b  |  40 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4.  
  5. #ifndef MSC
  6. #include <malloc.h>
  7. #endif
  8.  
  9. char far *Alloc( long );
  10. void Nomem( void );
  11.  
  12. char far *Alloc ( x ) /* allocate x bytes of far memory */
  13.     long x;
  14.     {
  15. #ifdef  MSC
  16.  
  17.     union REGS regs;
  18.  
  19.     regs.h.ah = 0x48; /* allocate memory dos call */
  20.     x = (x+15)>>4; /* get number of paragraphs to allocate */
  21.     regs.x.bx = (int)x;
  22.     intdos( ®s, ®s ); /* call dos; request memory */
  23.     if (regs.x.cflag) /* memory allocation error */
  24.         Nomem();
  25.     return( (char far *)((long)regs.x.ax<<16) ); /* make a far pointer */
  26.  
  27. #else
  28.         char far *p;
  29.  
  30.         p = (char far *) farmalloc( x );
  31.         if (p == NULL ) Nomem();
  32.         return( p );
  33. #endif
  34.     }
  35.  
  36. void Nomem () { /* a memory allocation request has failed */
  37.     fprintf( stderr, "out of memory\n" );
  38.     exit( -1 );
  39.     }
  40.