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.

84 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. membmgr2.hxx
  5. Abstract:
  6. This module contains the declarations for the MEM_ALLOCATOR
  7. class, which provides memory block of varialble size from
  8. a bigger block. All bigger blocks are then linked together
  9. thru a pointer at the end of each bigger block. This class
  10. is particularly suitable to user who needs a lot of small
  11. blocks but does not free any of them until there is no need
  12. to use the object anymore.
  13. Author:
  14. Daniel Chan (danielch) Oct 18, 1999
  15. --*/
  16. #if !defined( _MEM_ALLOCATOR_DEFN_ )
  17. #define _MEM_ALLOCATOR_DEFN_
  18. //
  19. // This class allocates a big buffer and then give a chunk of
  20. // it away each time Allocate is called. Each big buffer
  21. // is linked to the next one by having a pointer at the end
  22. // of the big buffer. The last buffer should have a NULL
  23. // pointer at the end of it.
  24. //
  25. class MEM_ALLOCATOR : public OBJECT {
  26. public:
  27. ULIB_EXPORT
  28. DECLARE_CONSTRUCTOR( MEM_ALLOCATOR );
  29. VIRTUAL
  30. ULIB_EXPORT
  31. ~MEM_ALLOCATOR(
  32. );
  33. NONVIRTUAL
  34. ULIB_EXPORT
  35. BOOLEAN
  36. Initialize(
  37. IN ULONG64 MaximumMemoryToUse DEFAULT -1,
  38. IN ULONG IncrementalBlockSize DEFAULT 1024*1024
  39. );
  40. NONVIRTUAL
  41. ULIB_EXPORT
  42. PVOID
  43. Allocate(
  44. IN ULONG SizeInBytes
  45. );
  46. private:
  47. NONVIRTUAL
  48. VOID
  49. Construct(
  50. );
  51. NONVIRTUAL
  52. VOID
  53. Destroy(
  54. );
  55. PVOID _head_ptr; // points to the first big buffer
  56. PVOID _next_free_ptr; // points to the free space of the current big buffer
  57. ULONG _free_space_in_current_block; // amount of user space that's free in the
  58. // current big buffer
  59. ULONG _incremental_size; // how large is each big buffer
  60. ULONG64 _max_mem_use;
  61. ULONG64 _mem_use;
  62. };
  63. #endif