Files
MediaPipe.NET/Mediapipe.Net/External/SerializedProtoVector.cs
Adwyzz (OLED Edition) cc7ed1ebd0 Fix critical memory leak (#22)
* fix examples (or at least try to)

* stuff

* Better dispose that

* Add video input options because I'm selfish

* THIS ONE MOTHERFUCKING FOR LOOP

* Remove unnecessary using

* Fix osu framework example

* Use stable `Google.Protobuf` package

* Add options to osu framework example

* Use same options on all examples

* Add framerate option

* Use framerate option

Co-authored-by: Speykious <speykious@gmail.com>
2022-02-21 17:07:15 +01:00

37 lines
1.1 KiB
C#

// Copyright (c) homuler and The Vignette Authors
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Google.Protobuf;
using Mediapipe.Net.Native;
namespace Mediapipe.Net.External
{
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct SerializedProtoVector
{
public SerializedProto* Data;
public int Size;
// TODO: This is looking just as sus as SerializedProto.Dispose().
// Should be investigated in the same way.
public void Dispose()
{
for (int i = 0; i < Size; i++)
Data[i].Dispose();
UnsafeNativeMethods.mp_api_SerializedProtoArray__delete(Data);
}
public List<T> Deserialize<T>(MessageParser<T> parser) where T : IMessage<T>
{
var protos = new List<T>(Size);
for (int i = 0; i < Size; i++)
protos.Add(Data[i].Deserialize(parser));
return protos;
}
}
}