1
0

MallocAllocator_pvt.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef MallocAllocator_pvt_H
  16. #define MallocAllocator_pvt_H
  17. #include "memory/MallocAllocator.h"
  18. #include "util/Identity.h"
  19. struct MallocAllocator_OnFreeJob;
  20. struct MallocAllocator_OnFreeJob {
  21. void (* callback)(void* callbackContext);
  22. void* callbackContext;
  23. struct MallocAllocator_OnFreeJob* next;
  24. };
  25. struct MallocAllocator_Allocation;
  26. struct MallocAllocator_Allocation {
  27. struct MallocAllocator_Allocation* next;
  28. size_t size;
  29. };
  30. /** Internal state for Allocator. */
  31. struct MallocAllocator_pvt;
  32. struct MallocAllocator_pvt
  33. {
  34. /** This allocator. */
  35. struct Allocator pub;
  36. /**
  37. * A linked list of the allocations made with this allocator.
  38. * These are all freed when the allocator is freed.
  39. */
  40. struct MallocAllocator_Allocation* allocations;
  41. /** A linked list of jobs which must be done when this allocator is freed. */
  42. struct MallocAllocator_OnFreeJob* onFree;
  43. /**
  44. * When this allocator is freed, lastSibling->nextSibling will be set to nextSibling
  45. * removing this allocator from the linked list.
  46. * GOTCHYA: if this is the first sibling, lastSibling will point to the parent and
  47. * in that case, lastSibling->firstChild becomes nextSibling.
  48. */
  49. struct MallocAllocator_pvt* lastSibling;
  50. /** A pointer to the next allocator which is a child of the same parent. */
  51. struct MallocAllocator_pvt* nextSibling;
  52. /** The first child allocator, this will be freed when this allocator is freed. */
  53. struct MallocAllocator_pvt* firstChild;
  54. /** The number of bytes which can be allocated by this allocator and all of its family. */
  55. int64_t* spaceAvailable;
  56. /** The number of bytes which can be allocated total. */
  57. size_t maxSpace;
  58. /** The number of bytes allocated by *this* allocator (but not it's children). */
  59. size_t allocatedHere;
  60. /** This is the location where the allocator was created. */
  61. const char* identFile;
  62. int identLine;
  63. /** For checking structure integrity. */
  64. Identity
  65. };
  66. /** The first ("genesis") allocator, not a child of any other allocator. */
  67. struct MallocAllocator_FirstCtx
  68. {
  69. /** The context for the first allocator. */
  70. struct MallocAllocator_pvt context;
  71. /** The actual storage location for the size limit. */
  72. int64_t spaceAvailable;
  73. };
  74. #endif