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