You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2021/01/29 20:50:20 UTC

[GitHub] [trafficserver] shinrich commented on a change in pull request #6241: Make Allocator.h less silly (no creepy "proto" object).

shinrich commented on a change in pull request #6241:
URL: https://github.com/apache/trafficserver/pull/6241#discussion_r567086211



##########
File path: include/tscore/Allocator.h
##########
@@ -108,29 +109,39 @@ class Allocator
     ink_freelist_madvise_init(&this->fl, name, element_size, chunk_size, alignment, advice);
   }
 
+  // Dummies
+  void
+  destroy_if_enabled(void *)
+  {
+  }
+  Allocator &
+  raw()
+  {
+    return *this;
+  }
+
 protected:
   InkFreeList *fl;
 };
 
 /**
-  Allocator for Class objects. It uses a prototype object to do
-  fast initialization. Prototype of the template class is created
-  when the fast allocator is created. This is instantiated with
-  default (no argument) constructor. Constructor is not called for
-  the allocated objects. Instead, the prototype is just memory
-  copied onto the new objects. This is done for performance reasons.
+  Allocator for Class objects.
 
 */
-template <class C> class ClassAllocator : public Allocator
+template <class C, bool Destruct_on_free_ = false> class ClassAllocator : private Allocator
 {
 public:
-  /** Allocates objects of the templated type. */
+  using Value_type                   = C;
+  static bool const Destruct_on_free = Destruct_on_free_;
+
+  /** Allocates objects of the templated type.  Arguments are forwarded to the constructor for the object. */
+  template <typename... Args>
   C *
-  alloc()
+  alloc(Args &&... args)
   {
     void *ptr = ink_freelist_new(this->fl);
 
-    memcpy(ptr, (void *)&this->proto.typeObject, sizeof(C));
+    ::new (ptr) C(std::forward<Args>(args)...);

Review comment:
       Running with ASAN seems to initialize the allocated memory to a highly probably "bad" pattern.  Once I fixed the cacheVC, the rest of the system seems to be running fine.  At least this explains why we didn't see the CacheVC::od problem before.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org