blob: dffbfa2a8a3346919d780259fbfbb1ca0543e17d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*
* 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
{
/// <summary>
/// Provides a way to allocate and manage opaque memory hanles for a cache entry data
/// </summary>
public interface ICacheEntryMemoryManager
{
/// <summary>
/// Allocates a new handle of at-least the specified size or larger.
/// </summary>
/// <param name="size">The desired minimum size of the handle</param>
/// <returns>A referrence to the newly allocated handle</returns>
object AllocHandle(uint size);
/// <summary>
/// Resizes the handle to the new size. Usually a larger size
/// than the current size.
/// </summary>
/// <param name="handle">A referrence to the existing handle</param>
/// <param name="newSize"></param>
void ResizeHandle(object handle, uint newSize);
/// <summary>
/// Frees the prevously allocated handle
/// </summary>
/// <param name="handle">A referrence to the previously allocated handle</param>
void FreeHandle(object handle);
/// <summary>
/// Pins the handle to the specified offset and returns a
/// <see cref="MemoryHandle"/> to the pinned memory block.
/// </summary>
/// <param name="handle"></param>
/// <param name="offset"></param>
/// <returns></returns>
MemoryHandle PinHandle(object handle, int offset);
/// <summary>
/// Gets the full usable size of the memory block held by the handle
/// </summary>
/// <returns>The number of bytes available for access</returns>
uint GetHandleSize(object handle);
/// <summary>
/// Gets a segment of the memory block held by the handle for reading/writing
/// </summary>
/// <param name="handle">A referrence to the handle object</param>
/// <param name="offset">The data offset in bytes for the start of the desired memory block</param>
/// <param name="length">The desired size of the block in bytes</param>
/// <returns>A span with the desired offset of the desired length</returns>
Span<byte> GetSpan(object handle, uint offset, uint length);
}
}
|