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.

232 lines
6.3 KiB

  1. /*
  2. * memory.h
  3. *
  4. * Copyright (c) 1993 - 1995 by DataBeam Corporation, Lexington, KY
  5. *
  6. * Abstract:
  7. * This is the interface file for the Memory class. Instances of this
  8. * class are used to pass data around the system.
  9. *
  10. * Each instance of this class maintains two pointers. The first is a
  11. * pointer to the reference data (or the source data) which this object
  12. * is responsible for representing. The second is a pointer to a copy
  13. * buffer, which is a piece of allocated memory that a Memory object
  14. * can copy the data into if necessary.
  15. *
  16. * When a Memory object is created, both of these addresses are passed
  17. * in to it. It does not, however, copy the data from the reference
  18. * buffer to the copy buffer just yet. If anyone asks the address of the
  19. * buffer, it will simply return the reference pointer. However, the
  20. * first time the buffer is locked, the data will be copied from the
  21. * reference buffer to the copy buffer for safe keeping. In essence,
  22. * the lock function tells the Memory object that someone is interested
  23. * in the data for longer than the reference buffer will remain valid.
  24. *
  25. * After the object is locked, a call to retrieve a memory pointer will
  26. * result in the copy pointer being returned.
  27. *
  28. * Each time the lock function is called, a lock count is incremented.
  29. * The copy operation only takes place the first time the buffer is
  30. * locked, however.
  31. *
  32. * In addition to maintaining a lock count, this object keeps a flag
  33. * indicating whether or not it has been freed by the allocator. This
  34. * freeing really means that the object is enabled to be freed as soon
  35. * as the lock count hits zero.
  36. *
  37. * Caveats:
  38. * None.
  39. *
  40. * Author:
  41. * James P. Galvin, Jr.
  42. */
  43. #ifndef _MEMORY2_H_
  44. #define _MEMORY2_H_
  45. /*
  46. * FreeStack
  47. * This is a list container that can be used to hold memory addresses.
  48. * This structure is used to keep information about each free stack. There
  49. * is one free stack for each size block being maintained by each memory
  50. * manager.
  51. */
  52. typedef struct
  53. {
  54. ULong block_size;
  55. ULong total_block_count;
  56. ULong current_block_count;
  57. ULong block_stack_offset;
  58. } FreeStack;
  59. typedef FreeStack * PFreeStack;
  60. /*
  61. * This type is used to represent a block number in the memory manager. This
  62. * is essentially an index used to uniquely identify each block being
  63. * maintained by an instance of this class.
  64. */
  65. typedef ULong BlockNumber;
  66. typedef BlockNumber * PBlockNumber;
  67. #define INVALID_BLOCK_NUMBER 0xffffffffL
  68. /*
  69. * This type is used to determine when a memory object should be destroyed.
  70. * When a memory object is created, this field is set by the owner. The owner
  71. * can then ask for the value of this field at any time to help determine when
  72. * the object should be destroyed. Essentially, this field indicates whether
  73. * the global lock count for the memory this object represents should be used
  74. * to determine when this object should be destroyed.
  75. */
  76. typedef enum
  77. {
  78. MEMORY_LOCK_NORMAL,
  79. MEMORY_LOCK_IGNORED
  80. } MemoryLockMode;
  81. /*
  82. * This is the class definition for the Memory class.
  83. */
  84. class Memory;
  85. typedef Memory * PMemory;
  86. class Memory
  87. {
  88. public:
  89. Memory (PUChar reference_ptr,
  90. ULong length,
  91. PUChar copy_ptr,
  92. BlockNumber block_number,
  93. MemoryLockMode memory_lock_mode);
  94. virtual ~Memory () { };
  95. PUChar GetPointer ()
  96. {
  97. return (Copy_Ptr);
  98. }
  99. ULong GetLength ()
  100. {
  101. return (Length);
  102. }
  103. BlockNumber GetBlockNumber ()
  104. {
  105. return (Block_Number);
  106. }
  107. MemoryLockMode GetMemoryLockMode ()
  108. {
  109. return (Memory_Lock_Mode);
  110. }
  111. private:
  112. ULong Length;
  113. PUChar Copy_Ptr;
  114. BlockNumber Block_Number;
  115. MemoryLockMode Memory_Lock_Mode;
  116. };
  117. /*
  118. * Memory (
  119. * PUChar reference_ptr,
  120. * ULong length,
  121. * PUChar copy_ptr,
  122. * PFreeStack free_stack,
  123. * BlockNumber block_number)
  124. *
  125. * Functional Description:
  126. * This is the constructor for the Memory class. All it does is
  127. * initialize the instance variable with the passed in values.
  128. *
  129. * Formal Parameters:
  130. * reference_ptr (i)
  131. * This is a pointer to the data that is to represented by this
  132. * Memory object.
  133. * length (i)
  134. * This is the length of the reference buffer.
  135. * copy_ptr (i)
  136. * This is the address of an allocated buffer that the Memory object
  137. * can use to preserve the contents of the reference buffer if a lock
  138. * operation occurs.
  139. * free_stack (i)
  140. * This is a pointer to a list container that the allocated memory
  141. * block came from. This field is not used internally, and is only
  142. * held here in order to improve the performance of the memory
  143. * manager that is using Memory objects.
  144. * block_number (i)
  145. * This is the block number for the memory block that is represented
  146. * by this object. This field is not used internally, and is only
  147. * held here in order to improve the performance of the memory
  148. * manager that is using Memory objects.
  149. *
  150. * Return Value:
  151. * None.
  152. *
  153. * Side Effects:
  154. * None.
  155. *
  156. * Caveats:
  157. * None.
  158. */
  159. /*
  160. * ~Memory ()
  161. *
  162. * Functional Description:
  163. * This is the destructor for the Memory class. It does nothing at this
  164. * time. Note that it is the responsibility of the memory manager that
  165. * is using Memory objects to free up the memory.
  166. *
  167. * Formal Parameters:
  168. * None.
  169. *
  170. * Return Value:
  171. * None.
  172. *
  173. * Side Effects:
  174. * None.
  175. *
  176. * Caveats:
  177. * None.
  178. */
  179. /*
  180. * ULong GetLength ()
  181. *
  182. * Functional Description:
  183. * This function retrieves the length of the data being represented by
  184. * this object.
  185. *
  186. * Formal Parameters:
  187. * None.
  188. *
  189. * Return Value:
  190. * The length of the data.
  191. *
  192. * Side Effects:
  193. * None.
  194. *
  195. * Caveats:
  196. * None.
  197. */
  198. /*
  199. * BlockNumber GetBlockNumber ()
  200. *
  201. * Functional Description:
  202. * This function retrieves the block number of the block that is being
  203. * represented by this object. This allows the memory manager to put the
  204. * memory block back into the stack very efficiently.
  205. *
  206. * Formal Parameters:
  207. * None.
  208. *
  209. * Return Value:
  210. * The block number of the internal memory block.
  211. *
  212. * Side Effects:
  213. * None.
  214. *
  215. * Caveats:
  216. * None.
  217. */
  218. #endif