home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 November / CICA_MS_Windows_CD-ROM_Walnut_Creek_November_1992.iso / win3 / programr / dpmi_lib / dpmi_v2.c < prev    next >
C/C++ Source or Header  |  1991-11-06  |  2KB  |  75 lines

  1. /* This file is DPMI_V2.C
  2. **
  3. ** this program shows allocating memory in the DPMI-enviroment
  4. ** compile with smallmodel,protected mode instuctions
  5. ** link with dpmiutil.obj
  6. */
  7.  
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <time.h>
  11. #include "DPMI.H"
  12. #include <dos.h>
  13.  
  14. typedef struct node {
  15.         unsigned long     num;
  16.         void far        *data ;
  17.         struct node far    *next ;
  18.         } NODE ;
  19.  
  20. void protected_program()
  21. {
  22.     FREEMEMINFO free;
  23.     NODE far *p,far *q;
  24.     unsigned long nodes=0;
  25.     unsigned nodesize ;
  26.     time_t t1,t2;
  27.  
  28.     getfreeinfo(&free);
  29.     printf("\n");
  30.     printfreeinfo(&free);
  31.  
  32.     printf("\nSet NodeSize (try 4092) : ");
  33.     scanf("%lu",&nodesize);
  34.  
  35.     time(&t1);
  36.  
  37.     for (q= NULL ;;q->next =p) {
  38.         p=q ;
  39.         if ((q=extmalloc(sizeof(NODE)))== NULL)
  40.             break;
  41.         if ((q->data=extmalloc((DWORD)nodesize))==NULL) {
  42.             extfree(q);
  43.             break;
  44.             }
  45.         q->num=nodes++;
  46.         }
  47.     printf("\n%lu nodes ; %lu seconds\n",nodes,time(&t2)-t1);
  48.     printf("Allocated %lu KB\n", (nodes* ((DWORD)nodesize)+sizeof(NODE))>>10 );
  49.  
  50.     getfreeinfo(&free);
  51.     printf("\n");
  52.     printfreeinfo(&free);
  53.  
  54.     printf("\nFree descriptor..\n");
  55.  
  56.     time(&t1);
  57.     for (;p!=NULL; p=q) {
  58.         q=p->next;
  59.         if (p->num != --nodes)
  60.         printf("list corrupt: nodes=%lu num=%lu\n",nodes,p->num);
  61.         extfree(p->data);
  62.         extfree(p);
  63.         }
  64.     time(&t2);
  65.     printf("..end\n");
  66.     printf("%lu seconds\n",t2-t1);
  67. }
  68.  
  69. void main()
  70. {
  71.     real_to_protected();
  72.     protected_program();
  73.     protected_to_real();
  74. }
  75.