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.

103 lines
3.1 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. ARENA.H
  5. Abstract:
  6. Standard Arena allocators.
  7. History:
  8. a-raymcc 23-Apr-96
  9. --*/
  10. #ifndef _ALLOC_H_
  11. #define _ALLOC_H_
  12. #include "corepol.h"
  13. class POLARITY CArena
  14. {
  15. virtual LPVOID Alloc(SIZE_T dwBytes) = 0;
  16. virtual LPVOID Realloc(LPVOID pOriginal, SIZE_T dwNewSize) = 0;
  17. virtual BOOL Free(LPVOID) = 0;
  18. };
  19. class POLARITY CWin32DefaultArena : public CArena
  20. {
  21. public:
  22. CWin32DefaultArena() {}
  23. ~CWin32DefaultArena() {}
  24. // Allocates dwBytes of memory using the standard WBEM allocator
  25. LPVOID Alloc(SIZE_T dwBytes) {return WbemMemAlloc(dwBytes);}
  26. // Reallocates the block from Alloc using the standard WBEM allocator
  27. LPVOID Realloc(LPVOID pOriginal, SIZE_T dwNewSize)
  28. {return WbemMemReAlloc(pOriginal, dwNewSize);}
  29. // Frees the block of memory from Alloc or Realloc using the standard
  30. // WBEM allocator
  31. BOOL Free(LPVOID pBlock) {return WbemMemFree(pBlock);}
  32. //
  33. // sets the heap used by the allocation functions. Will return false
  34. // if one is already set. Most likely this function will be called at
  35. // module initialization, such as DllMain. Calling this function
  36. // is optional when -- 1 ) You can accept using the ProcessHeap and
  37. // 2 ) You are guaranteed that no allocations will occur before
  38. // static initialization has occurred in this module.
  39. //
  40. static BOOL WbemHeapInitialize( HANDLE hHeap );
  41. static void WbemHeapFree( );
  42. // Explicitly define as __cdecl as these are causing backwards compatibility
  43. // issues WbemMemAlloc, WbemMemFree and WbemMemSize
  44. // This is the main allocator for the whole of WinMgmt. All parts
  45. // of WinMgmt which allocate memory through HeapAlloc and the
  46. // the likes should use this instead
  47. static LPVOID __cdecl WbemMemAlloc(SIZE_T dwBytes);
  48. // This is the main allocator for the whole of WinMgmt. This
  49. // reallocates a block returned through WbemMemAlloc
  50. static LPVOID WbemMemReAlloc(LPVOID pOriginal, SIZE_T dwNewSize);
  51. // This is the main allocator for the whole of WinMgmt. This
  52. // frees up a block returned through WbemMemAlloc or WbemMemReAlloc.
  53. static BOOL __cdecl WbemMemFree(LPVOID pBlock) ;
  54. static BSTR WbemSysAllocString(const wchar_t *wszString);
  55. static BSTR WbemSysAllocStringByteLen(const char *szString, UINT len);
  56. static INT WbemSysReAllocString(BSTR *, const wchar_t *wszString);
  57. static BSTR WbemSysAllocStringLen(const wchar_t *wszString, UINT);
  58. static int WbemSysReAllocStringLen(BSTR *, const wchar_t *wszString, UINT);
  59. static void WbemSysFreeString(BSTR bszString) {SysFreeString(bszString);}
  60. static BOOL WbemOutOfMemory();
  61. //Returns the size of an allocated block
  62. static SIZE_T __cdecl WbemMemSize(LPVOID pBlock);
  63. // Makes sure there is probably enough virtual memory available to
  64. // carry out an operation.
  65. static BOOL ValidateMemSize(BOOL bLargeValidation = FALSE);
  66. //
  67. static HANDLE GetArenaHeap();
  68. };
  69. #endif