/* * Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Data.Caching.ObjectCache * File: ICacheEntryMemoryManager.cs * * ICacheEntryMemoryManager.cs is part of VNLib.Data.Caching.ObjectCache which is part * of the larger VNLib collection of libraries and utilities. * * VNLib.Data.Caching.ObjectCache is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * VNLib.Data.Caching.ObjectCache is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ using System; using System.Buffers; namespace VNLib.Data.Caching { /// /// Provides a way to allocate and manage opaque memory hanles for a cache entry data /// public interface ICacheEntryMemoryManager { /// /// Allocates a new handle of at-least the specified size or larger. /// /// The desired minimum size of the handle /// A referrence to the newly allocated handle object AllocHandle(uint size); /// /// Resizes the handle to the new size. Usually a larger size /// than the current size. /// /// A referrence to the existing handle /// void ResizeHandle(object handle, uint newSize); /// /// Frees the prevously allocated handle /// /// A referrence to the previously allocated handle void FreeHandle(object handle); /// /// Pins the handle to the specified offset and returns a /// to the pinned memory block. /// /// /// /// MemoryHandle PinHandle(object handle, int offset); /// /// Gets the full usable size of the memory block held by the handle /// /// The number of bytes available for access uint GetHandleSize(object handle); /// /// Gets a segment of the memory block held by the handle for reading/writing /// /// A referrence to the handle object /// The data offset in bytes for the start of the desired memory block /// The desired size of the block in bytes /// A span with the desired offset of the desired length Span GetSpan(object handle, uint offset, uint length); } }