]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
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 | // +build ccalloc | |
19 | ||
20 | #include "allocator.h" | |
21 | #include "arrow/memory_pool.h" | |
22 | #include "helpers.h" | |
23 | ||
24 | struct mem_holder { | |
25 | std::unique_ptr<arrow::MemoryPool> owned_pool; | |
26 | arrow::MemoryPool* pool; | |
27 | }; | |
28 | ||
29 | ArrowMemoryPool arrow_create_memory_pool(bool enable_logging) { | |
30 | auto holder = std::make_shared<mem_holder>(); | |
31 | if (enable_logging) { | |
32 | holder->owned_pool.reset(new arrow::LoggingMemoryPool(arrow::default_memory_pool())); | |
33 | holder->pool = holder->owned_pool.get(); | |
34 | } else { | |
35 | holder->pool = arrow::default_memory_pool(); | |
36 | } | |
37 | ||
38 | return create_ref(holder); | |
39 | } | |
40 | ||
41 | void arrow_release_pool(ArrowMemoryPool pool) { | |
42 | release_ref<mem_holder>(pool); | |
43 | } | |
44 | ||
45 | int arrow_pool_allocate(ArrowMemoryPool pool, int64_t size, uint8_t** out) { | |
46 | auto holder = retrieve_instance<mem_holder>(pool); | |
47 | auto status = holder->pool->Allocate(size, out); | |
48 | if (!status.ok()) { | |
49 | return 1; | |
50 | } | |
51 | return 0; | |
52 | } | |
53 | ||
54 | void arrow_pool_free(ArrowMemoryPool pool, uint8_t* buffer, int64_t size) { | |
55 | auto holder = retrieve_instance<mem_holder>(pool); | |
56 | holder->pool->Free(buffer, size); | |
57 | } | |
58 | ||
59 | int arrow_pool_reallocate(ArrowMemoryPool pool, int64_t old_size, int64_t new_size, uint8_t** ptr) { | |
60 | auto holder = retrieve_instance<mem_holder>(pool); | |
61 | auto status = holder->pool->Reallocate(old_size, new_size, ptr); | |
62 | if (!status.ok()) { | |
63 | return 1; | |
64 | } | |
65 | return 0; | |
66 | } | |
67 | ||
68 | int64_t arrow_pool_bytes_allocated(ArrowMemoryPool pool) { | |
69 | auto holder = retrieve_instance<mem_holder>(pool); | |
70 | return holder->pool->bytes_allocated(); | |
71 | } |