8
8
using System . Runtime . CompilerServices ;
9
9
using System . Runtime . InteropServices ;
10
10
using System . Security ;
11
+ using __NativeMemory = global ::System . Runtime . InteropServices . NativeMemory ;
11
12
using __CallingConvention = global ::System . Runtime . InteropServices . CallingConvention ;
12
13
using __IntPtr = global ::System . IntPtr ;
13
14
@@ -110,7 +111,7 @@ internal static CharTraits<_CharT> __CreateInstance(global::Std.CharTraits.__Int
110
111
111
112
private static void * __CopyValue ( global ::Std . CharTraits . __Internal native )
112
113
{
113
- var ret = Marshal . AllocHGlobal ( sizeof ( global ::Std . CharTraits . __Internal ) ) ;
114
+ var ret = ( nint ) __NativeMemory . AlignedAlloc ( ( nuint ) sizeof ( global ::Std . CharTraits . __Internal ) , 16 ) ;
114
115
* ( global ::Std . CharTraits . __Internal * ) ret = native ;
115
116
return ret . ToPointer ( ) ;
116
117
}
@@ -143,7 +144,7 @@ internal protected virtual void Dispose(bool disposing, bool callNativeDtor)
143
144
NativeToManagedMap . TryRemove ( __Instance , out _ ) ;
144
145
DisposePartial ( disposing ) ;
145
146
if ( __ownsNativeInstance )
146
- Marshal . FreeHGlobal ( __Instance ) ;
147
+ __NativeMemory . AlignedFree ( ( void * ) __Instance ) ;
147
148
__Instance = IntPtr . Zero ;
148
149
}
149
150
}
@@ -243,7 +244,7 @@ internal static Allocator<_Tp> __CreateInstance(global::Std.Allocator.__Internal
243
244
244
245
private static void * __CopyValue ( global ::Std . Allocator . __Internal native )
245
246
{
246
- var ret = Marshal . AllocHGlobal ( sizeof ( global ::Std . Allocator . __Internal ) ) ;
247
+ var ret = ( nint ) __NativeMemory . AlignedAlloc ( ( nuint ) sizeof ( global ::Std . Allocator . __Internal ) , 16 ) ;
247
248
* ( global ::Std . Allocator . __Internal * ) ret = native ;
248
249
return ret . ToPointer ( ) ;
249
250
}
@@ -267,7 +268,7 @@ public Allocator()
267
268
var ___Tp = typeof ( _Tp ) ;
268
269
if ( ___Tp . IsAssignableFrom ( typeof ( sbyte ) ) )
269
270
{
270
- __Instance = Marshal . AllocHGlobal ( sizeof ( global ::Std . Allocator . __Internal ) ) ;
271
+ __Instance = ( nint ) __NativeMemory . AlignedAlloc ( ( nuint ) sizeof ( global ::Std . Allocator . __Internal ) , 16 ) ;
271
272
__ownsNativeInstance = true ;
272
273
__RecordNativeToManagedMapping ( __Instance , this ) ;
273
274
global ::Std . Allocator . __Internal . ctorc__N_std_N___1_S_allocator__C ( __Instance ) ;
@@ -290,7 +291,7 @@ internal protected virtual void Dispose(bool disposing, bool callNativeDtor)
290
291
NativeToManagedMap . TryRemove ( __Instance , out _ ) ;
291
292
DisposePartial ( disposing ) ;
292
293
if ( __ownsNativeInstance )
293
- Marshal . FreeHGlobal ( __Instance ) ;
294
+ __NativeMemory . AlignedFree ( ( void * ) __Instance ) ;
294
295
__Instance = IntPtr . Zero ;
295
296
}
296
297
}
@@ -439,7 +440,7 @@ internal static BasicString<_CharT, _Traits, _Allocator> __CreateInstance(global
439
440
440
441
private static void * __CopyValue ( global ::Std . BasicString . __Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C native )
441
442
{
442
- var ret = Marshal . AllocHGlobal ( sizeof ( global ::Std . BasicString . __Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C ) ) ;
443
+ var ret = ( nint ) __NativeMemory . AlignedAlloc ( ( nuint ) sizeof ( global ::Std . BasicString . __Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C ) , 16 ) ;
443
444
* ( global ::Std . BasicString . __Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C * ) ret = native ;
444
445
return ret . ToPointer ( ) ;
445
446
}
@@ -465,7 +466,7 @@ public BasicString()
465
466
var ___Allocator = typeof ( _Allocator ) ;
466
467
if ( ___CharT . IsAssignableFrom ( typeof ( sbyte ) ) && ___Traits . IsAssignableFrom ( typeof ( global ::Std . CharTraits < sbyte > ) ) && ___Allocator . IsAssignableFrom ( typeof ( global ::Std . Allocator < sbyte > ) ) )
467
468
{
468
- __Instance = Marshal . AllocHGlobal ( sizeof ( global ::Std . BasicString . __Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C ) ) ;
469
+ __Instance = ( nint ) __NativeMemory . AlignedAlloc ( ( nuint ) sizeof ( global ::Std . BasicString . __Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C ) , 16 ) ;
469
470
__ownsNativeInstance = true ;
470
471
__RecordNativeToManagedMapping ( __Instance , this ) ;
471
472
global ::Std . BasicString . __Internalc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C . ctorc__N_std_N___1_S_basic_string__C___N_std_N___1_S_char_traits__C___N_std_N___1_S_allocator__C ( __Instance ) ;
@@ -499,7 +500,7 @@ internal protected virtual void Dispose(bool disposing, bool callNativeDtor)
499
500
throw new ArgumentOutOfRangeException ( "_CharT, _Traits, _Allocator" , string . Join ( ", " , new [ ] { typeof ( _CharT ) . FullName , typeof ( _Traits ) . FullName , typeof ( _Allocator ) . FullName } ) , "global::Std.BasicString<_CharT, _Traits, _Allocator> maps a C++ template class and therefore it only supports a limited set of types and their subclasses: <sbyte, global::Std.CharTraits<sbyte>, global::Std.Allocator<sbyte>>." ) ;
500
501
}
501
502
if ( __ownsNativeInstance )
502
- Marshal . FreeHGlobal ( __Instance ) ;
503
+ __NativeMemory . AlignedFree ( ( void * ) __Instance ) ;
503
504
__Instance = IntPtr . Zero ;
504
505
}
505
506
}
0 commit comments