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.

137 lines
4.6 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * Dynamic array implementation class
  8. *
  9. * Abstract:
  10. *
  11. * This class contains definitions of functions which can't (or shouldn't)
  12. * be inlined. We use a separate implementation class because this allows us
  13. * to avoid the code bloat template classes produce; every instance of the
  14. * DynArray template can use the same version of each out-of-line member.
  15. *
  16. * The DynArray data members need to be declared here, because they are
  17. * used by DynArrayImpl.
  18. *
  19. * Created:
  20. *
  21. * 2/18/1999 agodfrey
  22. *
  23. * 6/10/1999 t-wehunt
  24. * + Added AddMultipleAt and DeleteMultipleAt methods.
  25. *
  26. * 8/16/2000 bhouse
  27. * + Changed to growth mechanics to be exponential
  28. *
  29. \**************************************************************************/
  30. //
  31. // There are some routines for sorting and positional add and delete that
  32. // are being removed. This #define is to make that process easier. When
  33. // DynSortArray is removed, the code protected by this #define should be
  34. // removed too.
  35. //
  36. // See pathselfintersectremover.hpp for the definition of DynSortArray.
  37. //
  38. #define USE_OBSOLETE_DYNSORTARRAY
  39. class DynArrayImpl
  40. {
  41. protected:
  42. // Constructor
  43. //
  44. // initalAllocation - the initial allocation, which can be global,
  45. // static or dynamic memory (or NULL)
  46. // allocSize - size of the initial allocation
  47. // (0 if there is none)
  48. // count - initial number of elements
  49. DynArrayImpl(void *initialAllocation, UINT allocSize, UINT count = 0);
  50. // Shrink the buffer so that it is just big enough for the items
  51. // the dynamic array holds.
  52. VOID ShrinkToSize(UINT eltSize);
  53. // Add space for new elements (if necessary). Does not update Count.
  54. // eltSize - size of each element
  55. // newElements - number of new elements
  56. // exactSize - no exponential growth
  57. GpStatus Grow(UINT eltSize, UINT newElements, BOOL exactSize = FALSE);
  58. // Add new, uninitialized elements, and return a pointer to them.
  59. // eltSize - size of each element
  60. // newElements - number of new elements
  61. void *AddMultiple(UINT eltSize, UINT newElements);
  62. // Add new elements, initializing them with the given data.
  63. // eltSize - size of each element
  64. // newElements - number of new elements
  65. // newData - the data to be copied into the new space
  66. GpStatus AddMultiple(UINT eltSize, UINT newElements, const void *newData);
  67. // Detach the data buffer from the dynamic array.
  68. // Allocates the buffer to detatch if it is the initial allocation.
  69. GpStatus DetachData(UINT eltSize, void **buffer);
  70. #ifdef USE_OBSOLETE_DYNSORTARRAY
  71. //
  72. // NOTE: These functions are used only by DynSortArray and it is being
  73. // discontinued. Do not use. These routines have horrible performance
  74. // characteristics.
  75. //
  76. // Add new, uninitialized elements, and return a pointer to them.
  77. // All data from index on is shift towards the end of the array to make room.
  78. // index - index from which to insert the new elements.
  79. // eltSize - size of each element
  80. // newElements - number of new elements
  81. // CAUTION! could cause a big performance hit if the array is large!
  82. void *AddMultipleAt(UINT eltSize, UINT index, UINT newElements);
  83. // Add new elements, initializing them with the given data.
  84. // All data from index on is shift towards the end of the array to make room.
  85. // eltSize - size of each element
  86. // index - index from which to insert the new elements.
  87. // newElements - number of new elements
  88. // newData - the data to be copied into the new space
  89. // CAUTION! could cause a big performance hit if the array is large!
  90. GpStatus AddMultipleAt(UINT eltSize, UINT index, UINT newElements, const void *newData);
  91. // Deletes one item from the array at the index'th position.
  92. // CAUTION! could cause a big performance hit if the array is large!
  93. GpStatus DeleteMultipleAt(UINT eltSize, UINT index, UINT numElements);
  94. #endif
  95. // Capacity, StepSize, AllocSize and Count are all measured in elements,
  96. // not bytes.
  97. enum {
  98. kMinCapacityGrowth = 16,
  99. kMaxCapacityGrowth = 8092
  100. };
  101. void *DataBuffer;
  102. void *InitialAllocation;
  103. UINT AllocSize;
  104. UINT Capacity;
  105. UINT Count;
  106. };