home *** CD-ROM | disk | FTP | other *** search
/ CD-X 3 / cdx_03.iso / melyviz / clxms.arj / EXAMPLE1.PRG < prev    next >
Encoding:
Text File  |  1994-04-19  |  5.4 KB  |  161 lines

  1. /* ===================================================================
  2.    The purpose of this example code is to demonstrate the use of the
  3.    ClipXMS() function.  You can compile this code and run it under a
  4.    variety of computer configurations and test the effect of using the
  5.    NOEMS and NOXMS environment settings.
  6.  
  7.    Compile this test program using the /n switch:
  8.       CLIPPER example1 /n
  9.    Link this test program with the ClipXMS .OBJ files:
  10.       RTLINK file example1, clipxms1, clipxms2
  11.    =================================================================== */
  12.  
  13.  
  14. FUNCTION Test()
  15. /* -------------------------------------------------------------------
  16.    This function simply calls the other three example functions.
  17.    ------------------------------------------------------------------- */
  18.     LOCAL GetList := {}
  19.     LOCAL lTestVMM := .F.
  20.  
  21.     CLEAR SCREEN
  22.  
  23.     // See if there is unmanaged extended memory.
  24.     IF !CheckExtMem()
  25.         ALERT("Unmanaged Extended Memory Was Not Detected", {"Continue"})
  26.     ENDIF
  27.  
  28.     // Print out ClipXMS() information
  29.     ClipXMSInfo()
  30.     ?
  31.     ? "Press any key to continue..."
  32.     INKEY(0)
  33.  
  34.     // Test Clipper's VMM system if requested
  35.     CLEAR SCREEN
  36.     @ 1, 0 SAY "Test Clipper's VMM system (Y/N)?" GET lTestVMM PICTURE "Y"
  37.     READ
  38.     IF lTestVMM
  39.         TestVMM()
  40.     ENDIF
  41.  
  42.     ?
  43.     ? "Example code is finished."
  44.  
  45.     RETURN(NIL)
  46.  
  47.  
  48.  
  49. FUNCTION CheckExtMem()
  50. /* -------------------------------------------------------------------
  51.    This example function can be used at the beginning of your Clipper
  52.     application to test for the presence of a memory manager when
  53.     available extended memory is present.  If a memory manager is not
  54.     present, but extended memory is available, this example function
  55.     will display ALERT() boxes informing the user they can enhance
  56.     performance of the Clipper application by loading a memory manager.
  57.    ------------------------------------------------------------------- */
  58.    LOCAL nExtMem
  59.  
  60.    nExtMem := ClipXMS(6)
  61.  
  62.    IF nExtMem > 200
  63.       // If there is more than 200K of unmanaged extended memory,
  64.       // inform the user they could enhance performance by loading
  65.       // a memory manager.  200K is an arbitrary but reasonable cutoff.
  66.  
  67.       ALERT( ;
  68.          "Unmanaged Extended Memory Has Been Detected!;" + ;
  69.          "Your computer has available extended memory,;" + ;
  70.          "but no memory manager loaded.", ;
  71.          {"Continue"})
  72.  
  73.       ALERT( ;
  74.          "For best performance of this application;" + ;
  75.          "you should load a memory manager such as;" + ;
  76.          "HIMEM.SYS in your CONFIG.SYS file.", ;
  77.          {"Continue"})
  78.  
  79.       ALERT( ;
  80.          "Loading a memory manager would make nearly;" + ;
  81.          LTRIM(STR(nExtMem)) + "K of extended memory available to this;" + ;
  82.          "application, enhancing its performance!", ;
  83.          {"OK"})
  84.  
  85.    ENDIF
  86.  
  87.    RETURN(nExtMem > 200)
  88.  
  89.  
  90.  
  91. FUNCTION ClipXMSInfo()
  92. /* -------------------------------------------------------------------
  93.    This example function prints out ClipXMS info returned by the ClipXMS()
  94.    function.  If you do not load a memory manager in your CONFIG.SYS, this
  95.     function will print out a warning message.
  96.    ------------------------------------------------------------------- */
  97.     LOCAL cExtMem
  98.  
  99.    ? "ClipXMS(1) (version number) = " + LTRIM(STR(ClipXMS(1) / 100))
  100.    ? "ClipXMS(2) (serial number)  = " + LTRIM(STR(ClipXMS(2)))
  101.    ? "ClipXMS(3) (EMS memory at startup) = " + LTRIM(STR(ClipXMS(3)))
  102.    ? "ClipXMS(4) (XMS memory at startup) = " + LTRIM(STR(ClipXMS(4)))
  103.    ? "ClipXMS(5) (Using EMS:1, XMS:2, Protected Mode:3)  = " + LTRIM(STR(ClipXMS(5)))
  104.    ? "ClipXMS(6) (extended memory if no EMS/XMS present) = " + LTRIM(STR(ClipXMS(6)))
  105.  
  106.    IF ClipXMS(6) > 0
  107.         cExtMem := LTRIM(STR(ClipXMS(6)))
  108.         ?
  109.         ? "******************************************************************"
  110.        ? "* Neither an EMS nor an XMS memory manager was found, but this   *"
  111.        ? "* computer does have " + cExtMem + "K of extended memory installed.  Use a" + SPACE(6 - LEN(cExtMem)) + "*"
  112.        ? "* memory manager such as HIMEM.SYS to improve the performance of *"
  113.        ? "* your Clipper applications !!!                                  *"
  114.         ? "******************************************************************"
  115.         ?
  116.    ENDIF
  117.  
  118.     RETURN(NIL)
  119.  
  120.  
  121.  
  122. FUNCTION TestVMM()
  123. /* -------------------------------------------------------------------
  124.    This function provides a simple test of Clipper's VM system, verifying
  125.     that ClipXMS is swapping memory properly.  For testing purposes you
  126.     can call this function in a test program and run the test program
  127.     using the //NOEMS and //NOXMS switches separately and together to see
  128.     their affect on program performance.
  129.  
  130.    In a memory swapping intensive test such as this, you may notice XMS
  131.     memory swapping is slightly slower than EMS memory swapping, but in
  132.     a real world program that difference is not noticeable.
  133.    ------------------------------------------------------------------- */
  134.    LOCAL MyArray[1000]
  135.    LOCAL nTemp1
  136.    LOCAL cChar
  137.  
  138.    FOR nTemp1 := 1 TO 1000
  139.        cChar := CHR(nTemp1 % 256)
  140.        MyArray[nTemp1] := REPLICATE(cChar, 1000)
  141.        ? nTemp1
  142.    NEXT nTemp1
  143.  
  144.    ?
  145.    ? "Press any key to test integrity of swapped memory..."
  146.    INKEY(0)
  147.  
  148.    FOR nTemp1 := 1 TO 1000
  149.        cChar := CHR(nTemp1 % 256)
  150.        IF !(MyArray[nTemp1] == REPLICATE(cChar, 1000))
  151.            ? "Error in array element" + LTRIM(STR(nTemp1))
  152.        ENDIF
  153.    NEXT nTemp1
  154.  
  155.     ? "Test completed."
  156.  
  157.     RETURN(NIL)
  158.  
  159.  
  160.  
  161.