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.

80 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 1993-1999 Microsoft Corporation
  3. Module Name:
  4. pool.h
  5. Abstract:
  6. Fixed size memory allocator headers.
  7. Author:
  8. Bill Bolosky [bolosky] 1993
  9. Revision History:
  10. --*/
  11. struct PoolEntry;
  12. struct PoolBlob;
  13. class Pool {
  14. public:
  15. Pool(
  16. unsigned objectSize,
  17. void * (*allocator)(unsigned) = NULL,
  18. unsigned blobSize = 16334, // a little under 16K
  19. void (*destructor)(void *) = NULL);
  20. Pool(
  21. unsigned objectSize,
  22. void * (*allocator)(void));
  23. ~Pool(void);
  24. void preAllocate(
  25. unsigned n);
  26. void *allocate(void);
  27. void free(
  28. void *object);
  29. unsigned numAllocations(void);
  30. unsigned numFrees(void);
  31. unsigned numNews(void);
  32. unsigned getObjectSize(void);
  33. private:
  34. PoolEntry *getEntry(void);
  35. void releaseEntry(
  36. PoolEntry *entry);
  37. void allocateMoreObjects(void);
  38. unsigned objectSize;
  39. void *(*countAllocator)(unsigned);
  40. void *(*singleAllocator)(void);
  41. void (*destructor)(void *);
  42. struct PoolEntry *entries; // PoolEntries with vaid data attached to them
  43. struct PoolEntry *freeEntries; // PoolEntries without valid data attached to them
  44. struct PoolBlob *entriesBlobHead; // The head of the blob list for PoolEntries
  45. unsigned entriesPerBlob; // How many entries in an entry blob
  46. struct PoolBlob *objectsBlobHead; // The head of the blob list for the allocated objects
  47. unsigned objectsPerBlob; // How many objects in an object blob
  48. unsigned allocations;
  49. unsigned frees;
  50. unsigned news;
  51. unsigned numFree; // Current size of free list
  52. };