@@ -102,25 +102,35 @@ class RFieldBase {
102102
103103 using ReadCallback_t = std::function<void (void *)>;
104104
105+ public:
106+ // / Maximum supported alignment for field types, i.e. maximum returned by GetAlignment()
107+ static constexpr std::size_t kMaxAlignment = 4096 ;
108+
105109protected:
106110 // / A functor to release the memory acquired by CreateValue() (memory and constructor).
107111 // / This implementation works for types with a trivial destructor. More complex fields implement a derived deleter.
108112 // / The deleter is operational without the field object and thus can be used to destruct/release a value after
109113 // / the field has been destructed.
110114 class RDeleter {
115+ std::size_t fAlignment ;
111116 public:
117+ explicit RDeleter (std::size_t alignment) : fAlignment(alignment)
118+ {
119+ R__ASSERT (fAlignment > 0 && fAlignment <= kMaxAlignment && ROOT::Internal::IsPowerOfTwo (fAlignment ));
120+ }
112121 virtual ~RDeleter () = default ;
113122 virtual void operator ()(void *objPtr, bool dtorOnly)
114123 {
115124 if (!dtorOnly)
116- operator delete (objPtr);
125+ operator delete (objPtr, fAlignment );
117126 }
118127 };
119128
120129 // / A deleter for templated RFieldBase descendents where the value type is known.
121130 template <typename T>
122131 class RTypedDeleter : public RDeleter {
123132 public:
133+ RTypedDeleter () : RDeleter(alignof (T)) {}
124134 void operator ()(void *objPtr, bool dtorOnly) final
125135 {
126136 std::destroy_at (static_cast <T *>(objPtr));
@@ -422,7 +432,7 @@ protected:
422432
423433 // / Constructs value in a given location of size at least GetValueSize(). Called by the base class' CreateValue().
424434 virtual void ConstructValue (void *where) const = 0;
425- virtual std::unique_ptr<RDeleter> GetDeleter () const { return std::make_unique<RDeleter>(); }
435+ virtual std::unique_ptr<RDeleter> GetDeleter () const { return std::make_unique<RDeleter>(GetAlignment () ); }
426436 // / Allow derived classes to call ConstructValue(void *) and GetDeleter() on other (sub)fields.
427437 static void CallConstructValueOn (const RFieldBase &other, void *where) { other.ConstructValue (where); }
428438 static std::unique_ptr<RDeleter> GetDeleterOf (const RFieldBase &other) { return other.GetDeleter (); }
@@ -552,9 +562,6 @@ protected:
552562 const ROOT ::RNTupleDescriptor *desc, ROOT ::DescriptorId_t fieldId);
553563
554564public:
555- // / Maximum supported alignment for field types, i.e. maximum returned by GetAlignment()
556- static constexpr std::size_t kMaxAlignment = 4096 ;
557-
558565 template <bool IsConstT>
559566 class RSchemaIteratorTemplate ;
560567 using RSchemaIterator = RSchemaIteratorTemplate<false >;
0 commit comments