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.

97 lines
2.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. memmngr.cpp
  7. memory manager for the WINS db object
  8. FILE HISTORY:
  9. Oct 13 1997 EricDav Created
  10. */
  11. #ifndef _MEMMNGR_H
  12. #define _MEMMNGR_H
  13. #include "afxmt.h"
  14. // the format of the record name is as follows:
  15. // Byte Description
  16. // 0 - 15 are for the name
  17. // 16 reserved, must be 0
  18. // 17 internal flags, the two low bits store the RECTYPE
  19. // defined in WINSINTF_RECTYPE_E
  20. // The upper 4 bits are reserved for internal use
  21. // 18 WINS flags (active, static, tombstoned)
  22. // 19 NameLength
  23. // 20 Static Record Type, WINSDB_UNIQUe etc
  24. // byte 15 is assumed to be the type
  25. typedef enum _WINSDB_INTERNAL
  26. {
  27. WINSDB_INTERNAL_LONG_NAME = 0x40,
  28. WINSDB_INTERNAL_DELETED = 0x80
  29. } WINSDB_INTERNAL;
  30. typedef struct _WinsDBRecord
  31. {
  32. char szRecordName [21];
  33. DWORD dwExpiration;
  34. DWORD_PTR dwIpAdd;
  35. LARGE_INTEGER liVersion;
  36. DWORD dwOwner;
  37. } WinsDBRecord, * LPWINSDBRECORD;
  38. #define IS_WINREC_LONGNAME(wRecord) ((wRecord)->dwNameLen > 16)
  39. #define IS_DBREC_LONGNAME(wdbRecord) ((wdbRecord)->szRecordName[17] & WINSDB_INTERNAL_LONG_NAME)
  40. #define RECORDS_PER_BLOCK 4080
  41. #define RECORD_SIZE sizeof(WinsDBRecord) // bytes
  42. #define BLOCK_SIZE RECORDS_PER_BLOCK * RECORD_SIZE
  43. typedef CArray<HGLOBAL, HGLOBAL> BlockArray;
  44. class CMemoryManager
  45. {
  46. public:
  47. CMemoryManager();
  48. ~CMemoryManager();
  49. private:
  50. BlockArray m_BlockArray;
  51. public:
  52. BlockArray* GetBlockArray()
  53. {
  54. return &m_BlockArray;
  55. };
  56. // Free's up all memory and pre-allocates one block
  57. HRESULT Initialize();
  58. // Free's up all memory
  59. HRESULT Reset();
  60. // verifies the given HROW is valid
  61. BOOL IsValidHRow(HROW hrow);
  62. // allocates a new block of memory
  63. HRESULT Allocate();
  64. // adds the record in the internal structure format
  65. HRESULT AddData(const WinsRecord & wRecord, LPHROW phrow);
  66. HRESULT GetData(HROW hrow, LPWINSRECORD pWinsRecord);
  67. HRESULT Delete(HROW hrow);
  68. private:
  69. LPWINSDBRECORD m_hrowCurrent;
  70. CCriticalSection m_cs;
  71. HANDLE m_hHeap;
  72. };
  73. extern void WinsRecordToWinsDbRecord(HANDLE hHeap, const WinsRecord & wRecord, const LPWINSDBRECORD pRec);
  74. extern void WinsDbRecordToWinsRecord(const LPWINSDBRECORD pDbRec, LPWINSRECORD pWRec);
  75. #endif //_MEMMNGR__