2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "memory_resource.h"
22 memory_resource** default_mr_ptr() {
23 /* library-local */ static memory_resource* default_mr =
24 new_delete_resource();
25 DEBUG_PRINT(&default_mr << " " << default_mr);
29 memory_resource* get_default_resource() {
31 return *default_mr_ptr();
34 void set_default_resource(memory_resource* mr) {
36 *default_mr_ptr() = mr;
39 memory_resource* new_delete_resource() {
40 class new_delete : public memory_resource {
44 const size_t alignment = folly::max_align_v) override {
46 void* p = static_cast<void*>(new char[bytes]);
47 DEBUG_PRINT(this << " " << p << " " << bytes);
53 const size_t alignment = folly::max_align_v) override {
56 DEBUG_PRINT(p << " " << bytes);
57 delete[] static_cast<char*>(p);