@@ -330,10 +330,12 @@ using Allocator = FreelistAllocator;
330330 Allocator for Class objects.
331331
332332*/
333- template <std::destructible C, typename BaseAllocator = Allocator> class ClassAllocator : public BaseAllocator
333+ template <std::destructible C, bool Destruct_on_free_ = true , typename BaseAllocator = Allocator>
334+ class ClassAllocator : public BaseAllocator
334335{
335336public:
336- using Value_type = C;
337+ using Value_type = C;
338+ static bool const Destruct_on_free = Destruct_on_free_;
337339
338340 /* * Allocates objects of the templated type. Arguments are forwarded to the constructor for the object. */
339341 template <typename ... Args>
@@ -380,19 +382,21 @@ template <std::destructible C, typename BaseAllocator = Allocator> class ClassAl
380382 void
381383 destroy_if_enabled (C *ptr)
382384 {
383- std::destroy_at (ptr);
385+ if constexpr (Destruct_on_free) {
386+ std::destroy_at (ptr);
387+ }
384388 }
385389
386390 // Ensure that C is big enough to hold a void pointer (when it's stored in the free list as raw memory).
387391 //
388392 static_assert (sizeof (C) >= sizeof (void *), " Can not allocate instances of this class using ClassAllocator" );
389393};
390394
391- template <class C > class TrackerClassAllocator : public ClassAllocator <C>
395+ template <class C , bool Destruct_on_free = true > class TrackerClassAllocator : public ClassAllocator <C, Destruct_on_free >
392396{
393397public:
394398 TrackerClassAllocator (const char *name, unsigned int chunk_size = 128 , unsigned int alignment = 16 )
395- : ClassAllocator<C>(name, chunk_size, alignment), allocations(0 ), trackerLock(PTHREAD_MUTEX_INITIALIZER)
399+ : ClassAllocator<C, Destruct_on_free >(name, chunk_size, alignment), allocations(0 ), trackerLock(PTHREAD_MUTEX_INITIALIZER)
396400 {
397401 }
398402
@@ -401,7 +405,7 @@ template <class C> class TrackerClassAllocator : public ClassAllocator<C>
401405 {
402406 void *callstack[3 ];
403407 int frames = backtrace (callstack, 3 );
404- C *ptr = ClassAllocator<C>::alloc ();
408+ C *ptr = ClassAllocator<C, Destruct_on_free >::alloc ();
405409
406410 const void *symbol = nullptr ;
407411 if (frames == 3 && callstack[2 ] != nullptr ) {
@@ -427,7 +431,7 @@ template <class C> class TrackerClassAllocator : public ClassAllocator<C>
427431 reverse_lookup.erase (it);
428432 }
429433 ink_mutex_release (&trackerLock);
430- ClassAllocator<C>::free (ptr);
434+ ClassAllocator<C, Destruct_on_free >::free (ptr);
431435 }
432436
433437private:
0 commit comments