Last change
on this file since 675 was 598, checked in by イグトランス (egtra), 17 years ago |
([597]でのコミット漏れ)より簡単なGC避けとしてObjectHandleを追加。
GCHandleの内部実装もObjectHandleベースへ移行。
|
File size:
1.7 KB
|
Line | |
---|
1 | ' Classes/System/Runtime/InteropServices/GCHandle.ab
|
---|
2 |
|
---|
3 | Namespace System
|
---|
4 | Namespace Runtime
|
---|
5 | Namespace InteropServices
|
---|
6 |
|
---|
7 | Class GCHandle
|
---|
8 | Public
|
---|
9 | Function Target() As Object
|
---|
10 | Target = ActiveBasic.GetObjectFromHandle(handle)
|
---|
11 | End Function
|
---|
12 |
|
---|
13 | Sub Target(obj As Object)
|
---|
14 | If handle <> 0 Then
|
---|
15 | ActiveBasic.ReleaseObjectHandle(handle)
|
---|
16 | End If
|
---|
17 | handle = ActiveBasic.AllocObjectHandle(obj)
|
---|
18 | End Sub
|
---|
19 |
|
---|
20 | Const Function IsAllocated() As Boolean
|
---|
21 | Return handle <> 0
|
---|
22 | End Function
|
---|
23 |
|
---|
24 | Static Function Alloc(obj As Object) As GCHandle
|
---|
25 | Alloc = New GCHandle
|
---|
26 | Alloc.Target = obj
|
---|
27 | End Function
|
---|
28 |
|
---|
29 | Sub Free()
|
---|
30 | If handle = 0 Then
|
---|
31 | Throw New InvalidOperationException
|
---|
32 | End If
|
---|
33 | ActiveBasic.ReleaseObjectHandle(handle)
|
---|
34 | handle = 0
|
---|
35 | End Sub
|
---|
36 |
|
---|
37 | Static Function ToIntPtr(h As GCHandle) As LONG_PTR
|
---|
38 | Return h.handle
|
---|
39 | End Function
|
---|
40 |
|
---|
41 | Static Function FromIntPtr(ip As LONG_PTR) As GCHandle
|
---|
42 | If ip = 0 Then
|
---|
43 | Throw New InvalidOperationException("GCHandle.FromIntPtr: ip is 0.")
|
---|
44 | End If
|
---|
45 | FromIntPtr = New GCHandle
|
---|
46 | FromIntPtr.handle = ip
|
---|
47 | End Function
|
---|
48 |
|
---|
49 | Override Function GetHashCode() As Long
|
---|
50 | Return _System_HashFromPtr(handle As VoidPtr)
|
---|
51 | End Function
|
---|
52 |
|
---|
53 | Function Equals(y As GCHandle) As Boolean
|
---|
54 | Return handle = y.handle
|
---|
55 | End Function
|
---|
56 |
|
---|
57 | Function Operator == (y As GCHandle) As Boolean
|
---|
58 | Return Equals(y)
|
---|
59 | End Function
|
---|
60 |
|
---|
61 | Function Operator <> (y As GCHandle) As Boolean
|
---|
62 | Return Not Equals(y)
|
---|
63 | End Function
|
---|
64 |
|
---|
65 | Override Function ToString() As String
|
---|
66 | Return "System.Runtime.InteropServices.GCHandle"
|
---|
67 | End Function
|
---|
68 |
|
---|
69 | Private
|
---|
70 | Sub GCHandle()
|
---|
71 | End Sub
|
---|
72 |
|
---|
73 | Private
|
---|
74 | handle As LONG_PTR
|
---|
75 | End Class
|
---|
76 |
|
---|
77 | End Namespace 'System
|
---|
78 | End Namespace 'Runtime
|
---|
79 | End Namespace 'InteropServices
|
---|
Note:
See
TracBrowser
for help on using the repository browser.