home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d571 / gwin.lha / Gwin / Examples / recovermem.c < prev    next >
C/C++ Source or Header  |  1991-12-22  |  2KB  |  46 lines

  1. #include "gwin.user.h"
  2. main()
  3. {
  4.  
  5. UBYTE *AllocMem(), *fake1, *fake2;
  6.  
  7.    /* What, you may ask, is this?  Well I usually test memory */
  8.    /* allocation/deallocation by checking to see if the       */
  9.    /* available memory is the same after I run my program     */
  10.    /* as it was before I run my program.  On the Amiga, it    */
  11.    /* is not.  Some sort of screwball accounting is being     */
  12.    /* done by the operating system so that if you used        */
  13.    /* diskfonts (which I do), the memory does not REALLY      */
  14.    /* free itself up until you try to allocate more than is   */
  15.    /* "virtually free".  By attempting to allocate a large    */
  16.    /* block of memory, (in this case, 10 megabytes which is   */
  17.    /* impossible) we fake the system out into freeing         */
  18.    /* everything so that we can tell if we forgot to free     */
  19.    /* our own personal memory.  If you check the memory that  */
  20.    /* appears to be available before running a program, that  */
  21.    /* opens a diskfont, then run the program, then look at    */
  22.    /* the memory availability again, it will look like you    */
  23.    /* forgot to release memory.  If you run recovermem, the   */
  24.    /* ACTUAL memory available will be reset to what it        */
  25.    /* REALLY is!                                              */
  26.  
  27.    /* This program will also remove libraries if their open   */
  28.    /* counts are 0.  All sorts of amazing things...           */
  29.  
  30.    /* I have put code similar to this in the uend routine     */
  31.    /* of GWIN.  It occurs right before the call to the user   */
  32.    /* cleanup handler.                                        */
  33.  
  34.  
  35.  
  36.    fake1 = AllocMem(10000000,MEMF_CHIP);
  37.    fake2 = AllocMem(10000000,MEMF_FAST);
  38.  
  39.    if(fake1) FreeMem(fake1,10000000);
  40.    if(fake2) FreeMem(fake2,10000000);
  41.  
  42.  
  43. }
  44.  
  45.  
  46.