Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
memory_pool.h
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #ifndef ARROW_MEMORY_POOL_H
19 #define ARROW_MEMORY_POOL_H
20 
21 #include <atomic>
22 #include <cstdint>
23 
24 #include "arrow/util/visibility.h"
25 
26 namespace arrow {
27 
28 class Status;
29 
34 class ARROW_EXPORT MemoryPool {
35  public:
36  virtual ~MemoryPool();
37 
41  virtual Status Allocate(int64_t size, uint8_t** out) = 0;
42 
47  virtual Status Reallocate(int64_t old_size, int64_t new_size, uint8_t** ptr) = 0;
48 
55  virtual void Free(uint8_t* buffer, int64_t size) = 0;
56 
59  virtual int64_t bytes_allocated() const = 0;
60 
65  virtual int64_t max_memory() const;
66 
67  protected:
68  MemoryPool();
69 };
70 
71 class ARROW_EXPORT LoggingMemoryPool : public MemoryPool {
72  public:
73  explicit LoggingMemoryPool(MemoryPool* pool);
74  virtual ~LoggingMemoryPool() = default;
75 
76  Status Allocate(int64_t size, uint8_t** out) override;
77  Status Reallocate(int64_t old_size, int64_t new_size, uint8_t** ptr) override;
78 
79  void Free(uint8_t* buffer, int64_t size) override;
80 
81  int64_t bytes_allocated() const override;
82 
83  int64_t max_memory() const override;
84 
85  private:
86  MemoryPool* pool_;
87 };
88 
89 ARROW_EXPORT MemoryPool* default_memory_pool();
90 
91 #ifdef ARROW_NO_DEFAULT_MEMORY_POOL
92 #define ARROW_MEMORY_POOL_DEFAULT
93 #else
94 #define ARROW_MEMORY_POOL_DEFAULT = default_memory_pool()
95 #endif
96 
97 } // namespace arrow
98 
99 #endif // ARROW_MEMORY_POOL_H
Definition: status.h:106
MemoryPool * default_memory_pool()
Top-level namespace for Apache Arrow C++ API.
Definition: allocator.h:29
Base class for memory allocation.
Definition: memory_pool.h:34
Definition: memory_pool.h:71