home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / heapprm.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  92 lines

  1. /***
  2. *heapprm.c - Set/report heap parameters
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Set or report the values of certain parameters in the heap.
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #ifndef WINHEAP
  13.  
  14.  
  15. #include <cruntime.h>
  16. #include <heap.h>
  17. #include <malloc.h>
  18. #include <mtdll.h>
  19.  
  20. /***
  21. *_heap_param(int flag, int param_id, void *pparam) - set or report the values
  22. *       of the specified heap parameter.
  23. *
  24. *Purpose:
  25. *       Get or set certain parameters which affect the behavior of the heap.
  26. *       The supported parameters vary implementation to implementation and
  27. *       version to version. See description of entry conditions for the
  28. *       currently supported parameters.
  29. *
  30. *Entry:
  31. *       int flag     - _HP_GETPARAM, to get a parameter value, or _HP_SETPARAM,
  32. *                      to set a parameter value
  33. *
  34. *       int param_id - identifier for the heap parameter. values supported in
  35. *                      this release are:
  36. *
  37. *                      _HP_AMBLKSIZ  - _amblksiz (aka _heap_growsize) parameter
  38. *                      _HP_GROWSIZE  - same as _HP_AMBLKSIZ
  39. *                      _HP_RESETSIZE - _heap_resetsize parameter
  40. *
  41. *       void *pparam - pointer to variable of appropriate type for the heap
  42. *                      parameter to be fetched/set
  43. *
  44. *Exit:
  45. *        0 = no error has occurred
  46. *       -1 = an error has occurred (errno is set)
  47. *
  48. *Exceptions:
  49. *
  50. *******************************************************************************/
  51.  
  52. int __cdecl _heap_param (
  53.         int flag,
  54.         int param_id,
  55.         void *pparam
  56.         )
  57. {
  58.  
  59.         switch ( param_id ) {
  60.  
  61.                 case _HP_RESETSIZE:
  62.                         if ( flag == _HP_SETPARAM ) {
  63.                                 _mlock(_HEAP_LOCK);
  64.                                 _heap_resetsize = *(unsigned *)pparam;
  65.                                 _munlock(_HEAP_LOCK);
  66.                         }
  67.                         else
  68.                                 *(unsigned *)pparam = _heap_resetsize;
  69.                         break;
  70.  
  71.                 case _HP_AMBLKSIZ:
  72.                         if ( flag == _HP_SETPARAM )
  73.                                 /*
  74.                                  * the only references to _amblksiz (aka
  75.                                  * _heap_growsize) are atomic. therefore, the
  76.                                  * heap does not need to be locked.
  77.                                  */
  78.                                 _amblksiz = *(unsigned *)pparam;
  79.                         else
  80.                                 *(unsigned *)pparam = _amblksiz;
  81.                         break;
  82.  
  83.                 default:
  84.                         return -1;
  85.         }
  86.  
  87.         return 0;
  88. }
  89.  
  90.  
  91. #endif  /* WINHEAP */
  92.