프로젝트

일반

사용자정보

통계
| 개정판:

t1 / TFDContents / Assets / Standard Assets / SmartGCHandle.cs @ 10

이력 | 보기 | 이력해설 | 다운로드 (916 Bytes)

1 3 KTH
#if !(UNITY_WSA_10_0 && NETFX_CORE)
2
using System;
3
using System.Collections.Generic;
4
using System.Runtime.InteropServices;
5
using System.Linq;
6
7
namespace Helper
8
{
9
    public class SmartGCHandle : IDisposable
10
    {
11
        private GCHandle handle;
12
        public SmartGCHandle(GCHandle handle)
13
        {
14
            this.handle = handle;
15
        }
16
17
        ~SmartGCHandle()
18
        {
19
            Dispose(false);
20
        }
21
22
        public System.IntPtr AddrOfPinnedObject()
23
        {
24
            return handle.AddrOfPinnedObject();
25
        }
26
27
        public virtual void Dispose()
28
        {
29
            Dispose(true);
30
        }
31
32
        protected virtual void Dispose(bool disposing)
33
        {
34
            this.handle.Free();
35
        }
36
37
        public static implicit operator GCHandle(SmartGCHandle other)
38
        {
39
40
            return other.handle;
41
        }
42
    }
43
}
44
#endif