Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:47

0001 /// \file ROOT/RPageAllocator.hxx
0002 /// \ingroup NTuple ROOT7
0003 /// \author Jakob Blomer <jblomer@cern.ch>
0004 /// \date 2019-06-25
0005 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
0006 /// is welcome!
0007 
0008 /*************************************************************************
0009  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0010  * All rights reserved.                                                  *
0011  *                                                                       *
0012  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0013  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0014  *************************************************************************/
0015 
0016 #ifndef ROOT7_RPageAllocator
0017 #define ROOT7_RPageAllocator
0018 
0019 #include <ROOT/RNTupleUtil.hxx>
0020 #include <ROOT/RPage.hxx>
0021 
0022 #include <cstddef>
0023 #include <functional>
0024 
0025 namespace ROOT {
0026 namespace Experimental {
0027 namespace Internal {
0028 
0029 // clang-format off
0030 /**
0031 \class ROOT::Experimental::Internal::RPageDeleter
0032 \ingroup NTuple
0033 \brief A closure that can free the memory associated with a mapped page
0034 
0035 The page pool, once taken ownership of pages, must know how to free them. When registering a new page with
0036 the page pool, the passed page deleter encapsulates that knowledge.
0037 */
0038 // clang-format on
0039 class RPageDeleter {
0040 private:
0041    /// The callable that is suppped to free the given page; it is called with fUserData as the second argument.
0042    std::function<void(const RPage &page, void *userData)> fFnDelete;
0043    /// Optionally additional information necessary to free resources associated with a page.  For instance,
0044    /// when the page is read from a TKey, user data points to the ROOT object created for reading, which needs to be
0045    /// freed as well.
0046    void *fUserData;
0047 
0048 public:
0049    RPageDeleter() : fFnDelete(), fUserData(nullptr) {}
0050    explicit RPageDeleter(decltype(fFnDelete) fnDelete) : fFnDelete(fnDelete), fUserData(nullptr) {}
0051    RPageDeleter(decltype(fFnDelete) fnDelete, void *userData) : fFnDelete(fnDelete), fUserData(userData) {}
0052    RPageDeleter(const RPageDeleter &other) = default;
0053    RPageDeleter &operator =(const RPageDeleter &other) = default;
0054    ~RPageDeleter() = default;
0055 
0056    void operator()(const RPage &page) { fFnDelete(page, fUserData); }
0057 };
0058 
0059 
0060 // clang-format off
0061 /**
0062 \class ROOT::Experimental::Internal::RPageAllocatorHeap
0063 \ingroup NTuple
0064 \brief Uses standard C++ memory allocation for the column data pages
0065 
0066 The page allocator acquires and releases memory for pages.  It does not populate the pages, the returned pages
0067 are empty but guaranteed to have enough contiguous space for the given number of elements.  While a common
0068 concrete implementation uses the heap, other implementations are possible, e.g. using arenas or mmap().
0069 */
0070 // clang-format on
0071 class RPageAllocatorHeap {
0072 public:
0073    /// Reserves memory large enough to hold nElements of the given size. The page is immediately tagged with
0074    /// a column id.
0075    static RPage NewPage(ColumnId_t columnId, std::size_t elementSize, std::size_t nElements);
0076    /// Releases the memory pointed to by page and resets the page's information
0077    static void DeletePage(const RPage &page);
0078 };
0079 
0080 } // namespace Internal
0081 } // namespace Experimental
0082 } // namespace ROOT
0083 
0084 #endif