CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
memory_manager.h
1#pragma once
2
3#include "system/object_ext.h"
4#include "system/idisposable.h"
5#include "system/buffers/memory_handle.h"
6
7namespace System {
8
9template<typename> class Memory;
10template<typename> class Span;
11
12namespace Buffers {
13
16template<typename T>
18{
19 typedef MemoryManager ThisType;
21
22 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
23 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
24
25public:
28 {
29 return Memory<T>(System::MakeSharedPtr(this), GetSpan().get_Length());
30 }
31
33 virtual Span<T> GetSpan() = 0;
34
37 virtual MemoryHandle Pin(int32_t elementIndex = 0) = 0;
38
40 virtual void Unpin() = 0;
41
43 void Dispose() override
44 {
45 Dispose(true);
46 }
47
48protected:
51 Memory<T> CreateMemory(int length) const
52 {
53 return Memory<T>(this, length);
54 }
55
59 Memory<T> CreateMemory(int start, int length)
60 {
61 return Memory<T>(this, start, length);
62 }
63
66 virtual void Dispose(bool disposing) = 0;
67};
68
69}} // namespace System::Buffers
Represents a handle to a block of memory.
Definition: memory_handle.h:14
Provides an abstraction for managing memory blocks.
Definition: memory_manager.h:18
Memory< T > CreateMemory(int start, int length)
Creates a Memory<T> instance representing a sub-range of this MemoryManager.
Definition: memory_manager.h:59
virtual MemoryHandle Pin(int32_t elementIndex=0)=0
Returns a handle to the memory that has been pinned so its address can be taken.
virtual void Unpin()=0
Indicates the memory can be moved again; unpins previously pinned memory.
void Dispose() override
Disposes the memory manager and releases any resources it holds.
Definition: memory_manager.h:43
Memory< T > CreateMemory(int length) const
Creates a Memory<T> instance representing this MemoryManager starting at offset 0.
Definition: memory_manager.h:51
virtual Span< T > GetSpan()=0
Returns a span wrapping the underlying memory.
virtual void Dispose(bool disposing)=0
Releases resources held by the manager.
virtual Memory< T > get_Memory()
Returns a Memory<T>.
Definition: memory_manager.h:27
Defines method that releases resources owned by the current object. Objects of this class should only...
Definition: idisposable.h:30
Represents a mutable memory segment backed by an array.
Definition: memory.h:154
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
Represents a contiguous region of arbitrary memory similar to C++20's std::span.
Definition: span.h:364
Definition: db_command.h:9
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1650