File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 3
3
4
4
using System ;
5
5
using System . IO ;
6
+ #if ! NETSTANDARD2_0
7
+ using System . Buffers ;
8
+ #endif
6
9
7
10
namespace ImageMagick ;
8
11
9
12
internal sealed unsafe class ByteArrayWrapper
10
13
{
14
+ #if ! NETSTANDARD2_0
15
+ private static readonly ArrayPool < byte > _pool = ArrayPool < byte > . Create ( 1024 * 1024 * 64 , 128 ) ;
16
+
17
+ private byte [ ] _bytes = _pool . Rent ( 8192 ) ;
18
+ #else
11
19
private byte [ ] _bytes = new byte [ 8192 ] ;
20
+ #endif
12
21
private int _offset = 0 ;
22
+
13
23
private int _length = 0 ;
14
24
25
+ #if ! NETSTANDARD2_0
26
+ ~ ByteArrayWrapper ( )
27
+ => _pool . Return ( _bytes ) ;
28
+
29
+ public byte [ ] GetBytes ( )
30
+ {
31
+ var result = new byte [ _length ] ;
32
+ Array . Copy ( _bytes , result , _length ) ;
33
+ return result ;
34
+ }
35
+
36
+ #else
15
37
public byte [ ] GetBytes ( )
16
38
{
17
39
ResizeBytes ( _length ) ;
18
40
return _bytes ;
19
41
}
20
42
43
+ #endif
21
44
public long Read ( IntPtr data , UIntPtr count , IntPtr user_data )
22
45
{
23
46
if ( data == IntPtr . Zero )
@@ -105,6 +128,16 @@ private void EnsureLength(int length)
105
128
ResizeBytes ( newLength ) ;
106
129
}
107
130
131
+ #if ! NETSTANDARD2_0
132
+ private void ResizeBytes ( int length )
133
+ {
134
+ var newBytes = _pool . Rent ( length ) ;
135
+ Array . Copy ( _bytes , newBytes , _bytes . Length ) ;
136
+ _pool . Return ( _bytes ) ;
137
+ _bytes = newBytes ;
138
+ }
139
+ #else
108
140
private void ResizeBytes ( int length )
109
141
=> Array . Resize ( ref _bytes , length ) ;
142
+ #endif
110
143
}
You can’t perform that action at this time.
0 commit comments