Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.6 KiB

  1. //
  2. // Universal Resource Consumer: Just an innocent stress program
  3. // Copyright (c) Microsoft Corporation, 1997, 1998, 1999
  4. //
  5. //
  6. // module: pagefile.cxx
  7. // author: silviuc
  8. // created: Fri Apr 10 16:01:57 1998
  9. //
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <stdarg.h>
  13. #include <windows.h>
  14. #include "error.hxx"
  15. #include "pagefile.hxx"
  16. #include "consume.hxx"
  17. //
  18. // Function:
  19. //
  20. // ConsumeAllPageFile
  21. //
  22. // Description:
  23. //
  24. // This function consumes as much page file as possible.
  25. // It remains active as a consumer of the page file. Whenever
  26. // it cannot allocate anymore it sleeps for a while then tries
  27. // again.
  28. //
  29. void ConsumeAllPageFile ()
  30. {
  31. MEMORYSTATUSEX MemoryInfo;
  32. LPVOID Region;
  33. SIZE_T RegionSize;
  34. DWORD Count;
  35. //
  36. // Try to eat page file. This will go on forever in the sense
  37. // that the moment somebody frees some memory we will eat it
  38. // immediately.
  39. //
  40. for (Count = 0, RegionSize = 0x100000; ; )
  41. {
  42. Region = VirtualAlloc (
  43. NULL,
  44. RegionSize,
  45. MEM_COMMIT,
  46. PAGE_READWRITE);
  47. if (Region == NULL)
  48. {
  49. Sleep (1000);
  50. //
  51. // We've got an allocation error.
  52. // Switch to 64K chunks and try again.
  53. //
  54. RegionSize = 0x10000;
  55. continue;
  56. }
  57. else
  58. {
  59. if (++Count % 16 == 0)
  60. printf (".");
  61. }
  62. }
  63. }
  64. //
  65. // end of module: pagefile.cxx
  66. //