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.

113 lines
3.2 KiB

  1. #include "precomp.h"
  2. /*
  3. * memory.cpp
  4. *
  5. * Copyright (c) 1993 - 1995 by DataBeam Corporation, Lexington, KY
  6. *
  7. * Abstract:
  8. * This is the implementation file for the Memory class. Instances of
  9. * this class represent chunks of data that are passed through a system.
  10. * This class is particularly useful in cases where a memory buffer
  11. * needs to be used in several different places, none of which know
  12. * about each other. This is because this class encapsulates things
  13. * like lock counts, which are useful for holding memory until
  14. * everyone that needs it is through.
  15. *
  16. * Note that this class does NOT do memory management. It is told by
  17. * a higher level memory manager where its buffers are, etc. For this
  18. * reason, this class does not do any platform specific calls.
  19. *
  20. * IMPORTANT NOTE:
  21. * This class SHOULD NEVER contain virtual member functions. This is
  22. * because of the Init() member than can be called as the "constructor"
  23. * of this class.
  24. *
  25. * Private Instance Variables:
  26. * Length
  27. * This is the length of the reference buffer.
  28. * Copy_Ptr
  29. * This is the address of the allocated buffer that this object
  30. * uses.
  31. *
  32. * Private Member Functions:
  33. * None.
  34. *
  35. * Caveats:
  36. * None.
  37. *
  38. * Author:
  39. * James P. Galvin, Jr.
  40. */
  41. const char *MemorySignature = "T120Memr";
  42. /*
  43. * Memory ()
  44. *
  45. * Public
  46. *
  47. * Functional Description:
  48. * This is the constructor for the Memory class. It just initializes
  49. * all instance variable, based on the passed in values.
  50. */
  51. Memory::Memory (
  52. PUChar reference_ptr,
  53. ULong length,
  54. PUChar copy_ptr) :
  55. Length (length),
  56. Copy_Ptr (copy_ptr),
  57. lLock (1),
  58. m_priority (HIGHEST_PRIORITY)
  59. {
  60. SIGNATURE_COPY(MemorySignature);
  61. /*
  62. * If the reference pointer is a valid pointer, then the pointer type
  63. * will be set to reference (indicating that the reference data has not
  64. * yet been copied). If the reference pointer is NULL, then this is
  65. * a memory allocation with no associated reference data, so set the
  66. * pointer type to copy.
  67. */
  68. if (reference_ptr != NULL)
  69. memcpy (Copy_Ptr, reference_ptr, (Int) Length);
  70. }
  71. /*
  72. * Init ()
  73. *
  74. * Public
  75. *
  76. * Functional Description:
  77. * This is the initializer for the Memory class, in the cases
  78. * where the space for an object has been allocated, without
  79. * calling the constructor. It just initializes
  80. * all instance variable, based on the passed in values.
  81. *
  82. * NOTE: Because of this use of the Memory class, it should NOT
  83. * contain any virtual functions.
  84. */
  85. Void Memory::Init (
  86. PUChar reference_ptr,
  87. ULong length,
  88. MemoryPriority priority,
  89. PUChar copy_ptr)
  90. {
  91. Length = length;
  92. Copy_Ptr = copy_ptr;
  93. lLock = 1;
  94. m_priority = priority;
  95. SIGNATURE_COPY(MemorySignature);
  96. /*
  97. * If the reference pointer is a valid pointer, then the pointer type
  98. * will be set to reference (indicating that the reference data has not
  99. * yet been copied). If the reference pointer is NULL, then this is
  100. * a memory allocation with no associated reference data, so set the
  101. * pointer type to copy.
  102. */
  103. if (reference_ptr != NULL)
  104. memcpy (Copy_Ptr, reference_ptr, (Int) Length);
  105. }