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
1.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. array.cxx
  5. Abstract:
  6. This file contains Array class implementation.
  7. Author:
  8. Jason Hartman (JasonHa) 2000-12-28
  9. Environment:
  10. User Mode
  11. --*/
  12. #include "precomp.hxx"
  13. template <class T>
  14. Array<T>::Array(
  15. SIZE_T StartLength
  16. )
  17. {
  18. Init();
  19. Expand(StartLength);
  20. return;
  21. }
  22. template <class T>
  23. Array<T>::Array(
  24. T *Data,
  25. SIZE_T Count
  26. )
  27. {
  28. Init();
  29. Set(Data, Count);
  30. return;
  31. }
  32. template <class T>
  33. SIZE_T
  34. Array<T>::Expand(
  35. SIZE_T NewLength
  36. )
  37. {
  38. if (NewLength > Length)
  39. {
  40. if (NewLength <= Size)
  41. {
  42. RtlZeroMemory(Buffer+Length, sizeof(T)*(NewLength-Length));
  43. Length = NewLength;
  44. }
  45. else
  46. {
  47. if (hHeap == NULL)
  48. {
  49. hHeap = GetProcessHeap();
  50. }
  51. if (hHeap != NULL)
  52. {
  53. T *NewBuffer;
  54. NewBuffer = (T *) ((Buffer == NULL) ?
  55. HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(T)*NewLength):
  56. HeapReAlloc(hHeap, HEAP_ZERO_MEMORY, Buffer, sizeof(T)*NewLength));
  57. if (NewBuffer != NULL)
  58. {
  59. Buffer = NewBuffer;
  60. Size = HeapSize(hHeap, 0, Buffer) / sizeof(T);
  61. Length = NewLength;
  62. }
  63. }
  64. }
  65. }
  66. return Length;
  67. }
  68. template <class T>
  69. void
  70. Array<T>::Set(
  71. T *Data,
  72. SIZE_T Count,
  73. SIZE_T Start
  74. )
  75. {
  76. if (Count+Start > Expand(Count+Start)) return;
  77. RtlCopyMemory(Buffer+Start, Data, sizeof(T)*Count);
  78. return;
  79. }
  80. template class Array<BOOL>;
  81. template class Array<CHAR>;
  82. template class Array<ULONG>;