Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RPageAllocator.hxx
Go to the documentation of this file.
1 /// \file ROOT/RPageAllocator.hxx
2 /// \ingroup NTuple ROOT7
3 /// \author Jakob Blomer <jblomer@cern.ch>
4 /// \date 2019-06-25
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_RPageAllocator
17 #define ROOT7_RPageAllocator
18 
19 #include <ROOT/RNTupleUtil.hxx>
20 #include <ROOT/RPage.hxx>
21 
22 #include <cstddef>
23 #include <functional>
24 
25 namespace ROOT {
26 namespace Experimental {
27 namespace Detail {
28 
29 // clang-format off
30 /**
31 \class ROOT::Experimental::Detail::RPageDeleter
32 \ingroup NTuple
33 \brief A closure that can free the memory associated with a mapped page
34 
35 The page pool, once taken ownership of pages, must know how to free them. When registering a new page with
36 the page pool, the passed page deleter encapsulates that knowledge.
37 */
38 // clang-format on
39 class RPageDeleter {
40 private:
41  /// The callable that is suppped to free the given page; it is called with fUserData as the second argument.
42  std::function<void(const RPage &page, void *userData)> fFnDelete;
43  /// Optionally additional information necessary to free resources associated with a page. For instance,
44  /// when the page is read from a TKey, user data points to the ROOT object created for reading, which needs to be
45  /// freed as well.
46  void *fUserData;
47 
48 public:
49  RPageDeleter() : fFnDelete(), fUserData(nullptr) {}
50  explicit RPageDeleter(decltype(fFnDelete) fnDelete) : fFnDelete(fnDelete), fUserData(nullptr) {}
51  RPageDeleter(decltype(fFnDelete) fnDelete, void *userData) : fFnDelete(fnDelete), fUserData(userData) {}
52  RPageDeleter(const RPageDeleter &other) = default;
53  RPageDeleter &operator =(const RPageDeleter &other) = default;
54  ~RPageDeleter() = default;
55 
56  void operator()(const RPage &page) { fFnDelete(page, fUserData); }
57 };
58 
59 
60 // clang-format off
61 /**
62 \class ROOT::Experimental::Detail::RPageAllocatorHeap
63 \ingroup NTuple
64 \brief Uses standard C++ memory allocation for the column data pages
65 
66 The page allocator acquires and releases memory for pages. It does not populate the pages, the returned pages
67 are empty but guaranteed to have enough contiguous space for the given number of elements. While a common
68 concrete implementation uses the heap, other implementations are possible, e.g. using arenas or mmap().
69 */
70 // clang-format on
71 class RPageAllocatorHeap {
72 public:
73  /// Reserves memory large enough to hold nElements of the given size. The page is immediately tagged with
74  /// a column id.
75  static RPage NewPage(ColumnId_t columnId, std::size_t elementSize, std::size_t nElements);
76  /// Releases the memory pointed to by page and resets the page's information
77  static void DeletePage(const RPage &page);
78 };
79 
80 } // namespace Detail
81 } // namespace Experimental
82 } // namespace ROOT
83 
84 #endif