/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SRC_TRACE_PROCESSOR_UTIL_BUMP_ALLOCATOR_H_ #define SRC_TRACE_PROCESSOR_UTIL_BUMP_ALLOCATOR_H_ #include <cmath> #include <cstdint> #include <cstring> #include <limits> #include <memory> #include <optional> #include <tuple> #include "perfetto/ext/base/circular_queue.h" #include "perfetto/ext/base/utils.h" namespace perfetto { namespace trace_processor { // A simple memory allocator which "bumps" a pointer to service allocations. // See [1] for more details for an overview of bump allocators. // // This implementation works by obtaining a large chunk of memory from the // system allocator (i.e. from malloc). Every allocation uses that chunk as long // as there is free space inside. Once an allocation is requested which does not // fit in that chunk, a new chunk is requested from the system. // // IMPORTANT: all allocations returned from this allocator are 8-aligned and // all allocation sizes must be a multiple of 8. // // IMPORTANT: this allocator can allocate a total of 4GB of memory (2^32). Once // this is exhausted, any further allocation will cause a CHECK. // // IMPORTANT: all allocations *must* be explicitly freed before destroying this // object. The destructor will CHECK if it detects any allocation which is // unfreed. // // [1] https://rust-hosted-langs.github.io/book/chapter-simple-bump.html class BumpAllocator { … }; } // namespace trace_processor } // namespace perfetto #endif // SRC_TRACE_PROCESSOR_UTIL_BUMP_ALLOCATOR_H_