@@ -39,22 +39,12 @@ namespace freenect
3939///
4040public class SwapBufferCollection < T > : IDisposable
4141{
42- /// <summary>
43- /// This small array takes care of mapping
44- /// where the data is and where their swapped indices are
45- /// </summary>
46- private int [ ] bufferIndicesMap ;
47-
42+
4843/// <summary>
4944/// GC handles for each of the buffers in this collection
5045/// </summary>
5146private GCHandle [ ] bufferHandles ;
5247
53- /// <summary>
54- /// Buffers for data
55- /// </summary>
56- private T [ ] [ ] buffers ;
57-
5848/// <summary>
5949/// Gets the buffer at the specified index
6050/// </summary>
@@ -65,7 +55,7 @@ public T[] this[int index]
6555{
6656get
6757{
68- return this . buffers [ this . bufferIndicesMap [ index ] ] ;
58+ return ( T [ ] ) this . bufferHandles [ index ] . Target ;
6959}
7060}
7161
@@ -104,14 +94,11 @@ public SwapBufferCollection(int numBuffers, int bufferSize)
10494this . Count = numBuffers ;
10595
10696// Allocate buffers and save pinned handles to them
107- this . bufferIndicesMap = new int [ numBuffers ] ;
10897this . bufferHandles = new GCHandle [ numBuffers ] ;
109- this . buffers = new T [ numBuffers ] [ ] ;
11098for ( int i = 0 ; i < numBuffers ; i ++ )
11199{
112- this . bufferIndicesMap [ i ] = i ;
113- this . buffers [ i ] = new T [ bufferSize ] ;
114- this . bufferHandles [ i ] = GCHandle . Alloc ( this . buffers [ i ] , GCHandleType . Pinned ) ;
100+ var buffer = new T [ bufferSize ] ;
101+ this . bufferHandles [ i ] = GCHandle . Alloc ( buffer , GCHandleType . Pinned ) ;
115102}
116103}
117104
@@ -127,7 +114,7 @@ public SwapBufferCollection(int numBuffers, int bufferSize)
127114/// </returns>
128115public IntPtr GetHandle ( int index )
129116{
130- return this . bufferHandles [ this . bufferIndicesMap [ index ] ] . AddrOfPinnedObject ( ) ;
117+ return this . bufferHandles [ index ] . AddrOfPinnedObject ( ) ;
131118}
132119
133120/// <summary>
@@ -154,9 +141,9 @@ public void Swap(int index1, int index2)
154141}
155142
156143// Swap
157- int tmp = this . bufferIndicesMap [ index1 ] ;
158- this . bufferIndicesMap [ index1 ] = this . bufferIndicesMap [ index2 ] ;
159- this . bufferIndicesMap [ index2 ] = tmp ;
144+ var tmp = this . bufferHandles [ index1 ] ;
145+ this . bufferHandles [ index1 ] = this . bufferHandles [ index2 ] ;
146+ this . bufferHandles [ index2 ] = tmp ;
160147}
161148
162149/// <summary>
0 commit comments