Changeset 369 for trunk


Ignore:
Timestamp:
Nov 3, 2007, 5:01:18 AM (17 years ago)
Author:
dai
Message:

GCにてヒープ領域判定処理を追加。更に高速化した。

Location:
trunk/Include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/api_system.sbp

    r328 r369  
    680680Declare Function HeapReAlloc Lib "kernel32" (hHeap As HANDLE, dwFlags As DWord, lpMem As VoidPtr, dwBytes As SIZE_T) As VoidPtr
    681681Declare Function HeapSize Lib "kernel32" (hHeap As HANDLE, dwFlags As DWord, lpMem As VoidPtr) As SIZE_T
     682Declare Function HeapValidate Lib "kernel32" (hHeap As HANDLE, dwFlags As DWord, lpMem As VoidPtr) As BOOL
    682683Declare Sub InitializeCriticalSection Lib "kernel32" (ByRef CriticalSection As CRITICAL_SECTION)
    683684Declare Function IsBadReadPtr Lib "kernel32" (lp As VoidPtr, ucb As ULONG_PTR) As BOOL
  • trunk/Include/system/gc.sbp

    r368 r369  
    3232Class _System_CGarbageCollection
    3333
     34    hHeap As HANDLE                             ' GC用のヒープ
     35
    3436    pMemoryObjects As *_System_MemoryObject     ' メモリオブジェクト
    3537    countOfMemoryObjects As Long                ' 管理するメモリオブジェクトの個数
     
    3840
    3941    isSweeping As Boolean   ' スウィープ中かどうか
     42
     43    minPtr As ULONG_PTR
     44    maxPtr As ULONG_PTR
    4045
    4146    ' クリティカルセクション
     
    123128        )
    124129
     130        hHeap = HeapCreate( 0, 0, 0 )
     131
    125132        pMemoryObjects = _System_calloc( 1 )
    126133        countOfMemoryObjects=0
     
    135142        ' スウィープ中かどうか
    136143        isSweeping = False
     144
     145        minPtr = &HFFFFFFFFFFFFFFFF As ULONG_PTR
     146        maxPtr = 0
    137147
    138148        'クリティカルセッションを生成
     
    249259            pMemoryObjects[countOfMemoryObjects].generationCount = 0
    250260
     261            If minPtr > new_ptr As ULONG_PTR Then
     262                minPtr = new_ptr As ULONG_PTR
     263            End If
     264            If maxPtr < ( new_ptr + size ) As ULONG_PTR Then
     265                maxPtr = ( new_ptr + size ) As ULONG_PTR
     266            End If
     267
    251268            countOfMemoryObjects++
    252269        LeaveCriticalSection(CriticalSection)
     
    277294
    278295        ' 実際のメモリバッファはインデックスの分だけ多めに確保する
    279         Dim ptr = HeapAlloc( _System_hProcessHeap, dwFlags, size + SizeOf( LONG_PTR ) ) + SizeOf( LONG_PTR )
     296        Dim ptr = HeapAlloc( hHeap, dwFlags, size + SizeOf( LONG_PTR ) ) + SizeOf( LONG_PTR )
    280297
    281298        ' 管理対象のメモリオブジェクトとして追加
     
    302319
    303320            pTempMemoryObject->size = size
    304             pTempMemoryObject->ptr = HeapReAlloc( _System_hProcessHeap, HEAP_ZERO_MEMORY, pTempMemoryObject->ptr - SizeOf(LONG_PTR), size + SizeOf(LONG_PTR) ) + SizeOf(LONG_PTR)
     321            pTempMemoryObject->ptr = HeapReAlloc( hHeap, HEAP_ZERO_MEMORY, pTempMemoryObject->ptr - SizeOf(LONG_PTR), size + SizeOf(LONG_PTR) ) + SizeOf(LONG_PTR)
     322
     323            If minPtr > pTempMemoryObject->ptr As ULONG_PTR Then
     324                minPtr = pTempMemoryObject->ptr As ULONG_PTR
     325            End If
     326            If maxPtr < ( pTempMemoryObject->ptr + size ) As ULONG_PTR Then
     327                maxPtr = ( pTempMemoryObject->ptr + size ) As ULONG_PTR
     328            End If
    305329
    306330        LeaveCriticalSection(CriticalSection)
     
    324348                iAllSize -= pTempMemoryObject->size
    325349
    326                 HeapFree( _System_hProcessHeap, 0, pTempMemoryObject->ptr - SizeOf(LONG_PTR) )
     350                HeapFree( hHeap, 0, pTempMemoryObject->ptr - SizeOf(LONG_PTR) )
    327351                pTempMemoryObject->ptr = NULL
    328352                pTempMemoryObject->size = 0
     
    387411    Function HitTest(pSample As VoidPtr) As Long
    388412        If pSample = NULL Then
     413            Return -1
     414        End If
     415        If not( minPtr <= pSample and pSample <= maxPtr ) Then
    389416            Return -1
    390417        End If
     
    628655
    629656        ' マークリストを生成
    630         Dim pbMark = HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,countOfMemoryObjects*SizeOf(Byte)) As *Byte
     657        Dim pbMark = _System_calloc(countOfMemoryObjects*SizeOf(Byte)) As *Byte
    631658
    632659        ' グローバル領域をルートに指定してスキャン
     
    649676
    650677        'マークリストを解放
    651         HeapFree(_System_hProcessHeap,0,pbMark)
     678        _System_free(pbMark)
    652679
    653680        If iBackAllSize <= iAllSize * 2 Then
Note: See TracChangeset for help on using the changeset viewer.