aboutsummaryrefslogtreecommitdiffstatsci
path: root/vulkan/PinnedObjects.cs
blob: da14f2608a919b3193c579d9f6aab17401da8a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Vulkan {
	/// <summary>
	/// Keep pinned object gc handles and free them on dispose.
	/// </summary>
	public class PinnedObjects : IDisposable {
		public readonly List<GCHandle> Handles = new List<GCHandle> ();

		public void Dispose () {
			for (int i = Handles.Count - 1; i >= 0; i--)
				Handles[i].Free ();
			GC.SuppressFinalize (this);
		}
	}
}