Last change
on this file since 676 was 598, checked in by イグトランス (egtra), 17 years ago |
([597]でのコミット漏れ)より簡単なGC避けとしてObjectHandleを追加。
GCHandleの内部実装もObjectHandleベースへ移行。
|
File size:
1.7 KB
|
Line | |
---|
1 | 'Classes/ActiveBasic/ObjectHandle.ab
|
---|
2 |
|
---|
3 | /*!
|
---|
4 | @file
|
---|
5 | @brief GC避け用のオブジェクトハンドルについての関数群。
|
---|
6 | */
|
---|
7 |
|
---|
8 | Namespace ActiveBasic
|
---|
9 |
|
---|
10 | /*!
|
---|
11 | @brief オブジェクトハンドルを確保する。
|
---|
12 | @param[in] obj ハンドル化したいオブジェクト
|
---|
13 | @return ハンドル
|
---|
14 | @throw ArgumentNullException objがNothingのとき
|
---|
15 | @throw OutOfMemoryException ハンドル領域の確保ができなかったとき
|
---|
16 | @date 2008/08/13
|
---|
17 | @auther Egtra
|
---|
18 | */
|
---|
19 | Function AllocObjectHandle(obj As Object) As LONG_PTR
|
---|
20 | If IsNothing(obj) Then
|
---|
21 | Throw New System.ArgumentNullException("obj")
|
---|
22 | End If
|
---|
23 | Detail.handleList.Add(obj)
|
---|
24 | AllocObjectHandle = ObjPtr(obj) As LONG_PTR
|
---|
25 | End Function
|
---|
26 |
|
---|
27 | /*!
|
---|
28 | @brief オブジェクトハンドルからオブジェクトを得る。
|
---|
29 | @param[in] h ハンドル
|
---|
30 | @return 対応するオブジェクト
|
---|
31 | @throw ArgumentNullException hが0のとき
|
---|
32 | @date 2008/08/13
|
---|
33 | @auther Egtra
|
---|
34 | */
|
---|
35 | Function GetObjectFromHandle(h As LONG_PTR) As Object
|
---|
36 | If h = 0 Then
|
---|
37 | Throw New System.ArgumentNullException("h")
|
---|
38 | End If
|
---|
39 | GetObjectFromHandle = _System_PtrObj(h As VoidPtr)
|
---|
40 | System.Diagnostics.Debug.Assert(Not IsNothing(GetObjectFromHandle))
|
---|
41 | End Function
|
---|
42 |
|
---|
43 | /*!
|
---|
44 | @brief オブジェクトハンドルを解放する。
|
---|
45 | @param[in] h ハンドル
|
---|
46 | @return 対応するオブジェクト
|
---|
47 | @throw ArgumentNullException hが0のとき
|
---|
48 | @date 2008/08/13
|
---|
49 | @auther Egtra
|
---|
50 | */
|
---|
51 | Function ReleaseObjectHandle(h As LONG_PTR) As Object
|
---|
52 | If h = 0 Then
|
---|
53 | Throw New System.ArgumentNullException("h")
|
---|
54 | End If
|
---|
55 | ReleaseObjectHandle = _System_PtrObj(h As VoidPtr)
|
---|
56 | Detail.handleList.Remove(ReleaseObjectHandle)
|
---|
57 | System.Diagnostics.Debug.Assert(Not IsNothing(ReleaseObjectHandle))
|
---|
58 | End Function
|
---|
59 |
|
---|
60 | Namespace Detail
|
---|
61 | Dim handleList = New System.Collections.Generic.List<Object>
|
---|
62 | End Namespace
|
---|
63 |
|
---|
64 | End Namespace
|
---|
Note:
See
TracBrowser
for help on using the repository browser.