NVIDIA Holoscan SDK v3.4.0

Program Listing for File first_fit_allocator_base.hpp

Return to documentation for file (include/holoscan/core/resources/gxf/first_fit_allocator_base.hpp)

Copy
Copied!
            

/* * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * 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 HOLOSCAN_CORE_RESOURCES_GXF_FIRST_FIT_ALLOCATOR_BASE_HPP #define HOLOSCAN_CORE_RESOURCES_GXF_FIRST_FIT_ALLOCATOR_BASE_HPP #include <cstdint> #include <memory> #include <new> #include <utility> #include "holoscan/core/expected.hpp" namespace holoscan { class FirstFitAllocatorBase { public: enum class Error { kAlreadyInUse, kInvalidSize, kOutOfMemory, kBlockNotAllocated, kLogicError, }; template <typename T> using expected_t = expected<T, Error>; using unexpected_t = unexpected<Error>; FirstFitAllocatorBase(); expected_t<void> allocate(int32_t size); expected_t<int32_t> acquire(int32_t size); expected_t<void> release(int32_t index); private: struct Memory { void update(const Memory& left_child, const Memory& right_child); void set(int32_t free); int32_t left; int32_t right; int32_t max; int32_t size; }; void propagate_to_root(int32_t idx); void update(int32_t left, int32_t right, int32_t free); std::unique_ptr<Memory[]> tree_; int32_t size_; int32_t last_layer_first_index_; }; } // namespace holoscan #endif// HOLOSCAN_CORE_RESOURCES_GXF_FIRST_FIT_ALLOCATOR_BASE_HPP

© Copyright 2022-2025, NVIDIA. Last updated on Jul 1, 2025.