home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / memory / local / locshrnk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.0 KB  |  68 lines

  1. /**************************************************************************
  2.  *    LOCSHRNK    version 1.00
  3.  *
  4.  * This program tests the LocalShrink function, which shrinks the size of
  5.  * the local heap and returns the current size. If the shrinksize is larger
  6.  * than the current size, it will only return the current size.
  7.  *
  8.  * Using NULL for the first parameter will default to the current data
  9.  * segment.
  10.  *
  11.  * compiled on IBM AT w640K EGA running WINDOWS 2.03
  12.  **************************************************************************/
  13.  
  14. #include <windows.h>
  15. #include <stdio.h>
  16.  
  17. #define    MADMAX    45000
  18. #define    MAXHEAP    20480
  19. #define    HEAPSIZE    2048
  20.  
  21. int PASCAL            WinMain(HANDLE,HANDLE,LPSTR,int);
  22.  
  23. char    szPurpose[80] = "This is a program to initialize the local heap";
  24.  
  25. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  26. HANDLE   hInstance;
  27. HANDLE   hPrevInstance;
  28. LPSTR    lpszCmdLine;
  29. int      cmdShow;
  30. {
  31.         HANDLE   hMemBlock;
  32.         char       MesBuf[250];
  33.         DWORD       dwMemSize;
  34.  
  35.    MessageBox(GetFocus(),(LPSTR)szPurpose,(LPSTR)"LOCINIT",MB_OK);
  36.  
  37.     /* Get size of local heap by giving meaningless shrink value */
  38.    dwMemSize = LocalShrink(NULL, MADMAX);
  39.  
  40.    sprintf(MesBuf,"%s%lu","Size of local heap: ",dwMemSize);
  41.    MessageBox(GetFocus(),(LPSTR)MesBuf,(LPSTR)"LocolShrink",MB_OK);
  42.  
  43.     /* Increase the size of the local heap */
  44.    hMemBlock = LocalAlloc(LMEM_ZEROINIT | LMEM_MOVEABLE,(WORD)MAXHEAP);
  45.  
  46.    /* Get new size */
  47.    dwMemSize = LocalShrink(NULL, MADMAX);
  48.  
  49.    sprintf(MesBuf,"%s%lu","New size of local heap: ",dwMemSize);
  50.    MessageBox(GetFocus(),(LPSTR)MesBuf,(LPSTR)"Shrink",MB_OK);
  51.  
  52.     LocalFree(hMemBlock);
  53.  
  54.    /* Shrink local heap down to original size */
  55.    dwMemSize = LocalShrink(NULL, HEAPSIZE);
  56.  
  57.    sprintf(MesBuf,"Size of local heap after actually shrinking: %lu",
  58.        dwMemSize);
  59.    MessageBox(GetFocus(),(LPSTR)MesBuf,(LPSTR)"Shrink",MB_OK);
  60.  
  61.    MessageBox(GetFocus(),(LPSTR)"Initialized and Accessed Local Heap Succesful",
  62.        (LPSTR)"LocalInit",MB_OK);
  63.    
  64.    return (0);
  65. } /* WINMAIN */
  66.  
  67.  
  68.