/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App.CsWin32/ComHeapPtr`1.cs
47 строк
945 B
yair100
Code Quality: Updated headers
01 июл 2026, 06:18
01 июл 2026, 06:18
c27305a
Код
Авторство
О чём код?
// Copyright (c) Files Community // SPDX-License-Identifier: MPL-2.0 using System; using System.Runtime.CompilerServices; namespace Windows.Win32 { /// <summary> /// Contains a heap pointer allocated via CoTaskMemAlloc and a set of methods to work with the pointer safely. /// </summary> public unsafe struct ComHeapPtr<T> : IDisposable where T : unmanaged { private T* _ptr; public bool IsNull => _ptr == null; public ComHeapPtr(T* ptr) { _ptr = ptr; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly T* Get() { return _ptr; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly T** GetAddressOf() { return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { T* ptr = _ptr; if (ptr is not null) { _ptr = null; PInvoke.CoTaskMemFree((void*)ptr); } } } }