Source code of Windows XP (NT5)
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.

84 lines
2.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: PAGEMAN.HXX
  7. //
  8. // Contents: Page manager.
  9. //
  10. // History: 06-Aug-92 KyleP Added copyright
  11. // 06-Aug-92 KyleP Kernel implementation
  12. //
  13. //--------------------------------------------------------------------------
  14. #pragma once
  15. #define PAGE_SIZE 4096
  16. //+-------------------------------------------------------------------------
  17. //
  18. // Class: CPageManager
  19. //
  20. // Purpose: Manage pages
  21. //
  22. // History: 25-Dec-92 BartoszM Created
  23. //
  24. // Notes: Merry Christmas!
  25. //
  26. //--------------------------------------------------------------------------
  27. class CPageManager
  28. {
  29. public:
  30. static void* GetPage( unsigned ccPage = 1 );
  31. static void FreePage ( void* page );
  32. };
  33. //+-------------------------------------------------------------------------
  34. //
  35. // Member: CPageManager::GetPage, public
  36. //
  37. // Synopsis: Gets a page.
  38. //
  39. // History: 25-Dec-91 KyleP Created
  40. // 02-Aug-93 KyleP Just use heap to allocate memory.
  41. //
  42. // Notes: The kernel heap is smart enough to allocate large chunks
  43. // of memory directly from the memory manager.
  44. //
  45. //--------------------------------------------------------------------------
  46. inline void* CPageManager::GetPage( unsigned ccPage /* = 1 */ )
  47. {
  48. void * p = VirtualAlloc ( 0, ccPage * PAGE_SIZE, MEM_COMMIT, PAGE_READWRITE );
  49. if ( 0 == p )
  50. {
  51. THROW( CException( STATUS_INSUFFICIENT_RESOURCES ) );
  52. }
  53. return(p);
  54. }
  55. //+-------------------------------------------------------------------------
  56. //
  57. // Member: CPageManager::FreePage, public
  58. //
  59. // Synopsis: Frees a page.
  60. //
  61. // History: 25-Dec-91 KyleP Created
  62. //
  63. //--------------------------------------------------------------------------
  64. inline void CPageManager::FreePage ( void* page )
  65. {
  66. if (page == 0)
  67. {
  68. return;
  69. }
  70. VirtualFree ( page, 0, MEM_RELEASE );
  71. }