88using System . Runtime . CompilerServices ;
99using System . Runtime . InteropServices ;
1010using System . Security ;
11+ using __NativeMemory = global ::System . Runtime . InteropServices . NativeMemory ;
1112using __CallingConvention = global ::System . Runtime . InteropServices . CallingConvention ;
1213using __IntPtr = global ::System . IntPtr ;
1314
@@ -110,7 +111,7 @@ internal static CharTraits<_CharT> __CreateInstance(global::Std.CharTraits.__Int
110111
111112 private static void * __CopyValue ( global ::Std . CharTraits . __Internal native )
112113 {
113- var ret = Marshal . AllocHGlobal ( sizeof ( global ::Std . CharTraits . __Internal ) ) ;
114+ var ret = ( nint ) __NativeMemory . AlignedAlloc ( ( nuint ) sizeof ( global ::Std . CharTraits . __Internal ) , 16 ) ;
114115 * ( global ::Std . CharTraits . __Internal * ) ret = native ;
115116 return ret . ToPointer ( ) ;
116117 }
@@ -143,7 +144,7 @@ internal protected virtual void Dispose(bool disposing, bool callNativeDtor)
143144 NativeToManagedMap . TryRemove ( __Instance , out _ ) ;
144145 DisposePartial ( disposing ) ;
145146 if ( __ownsNativeInstance )
146- Marshal . FreeHGlobal ( __Instance ) ;
147+ __NativeMemory . AlignedFree ( ( void * ) __Instance ) ;
147148 __Instance = IntPtr . Zero ;
148149 }
149150 }
@@ -243,7 +244,7 @@ internal static Allocator<_Tp> __CreateInstance(global::Std.Allocator.__Internal
243244
244245 private static void * __CopyValue ( global ::Std . Allocator . __Internal native )
245246 {
246- var ret = Marshal . AllocHGlobal ( sizeof ( global ::Std . Allocator . __Internal ) ) ;
247+ var ret = ( nint ) __NativeMemory . AlignedAlloc ( ( nuint ) sizeof ( global ::Std . Allocator . __Internal ) , 16 ) ;
247248 * ( global ::Std . Allocator . __Internal * ) ret = native ;
248249 return ret . ToPointer ( ) ;
249250 }
@@ -267,7 +268,7 @@ public Allocator()
267268 var ___Tp = typeof ( _Tp ) ;
268269 if ( ___Tp . IsAssignableFrom ( typeof ( sbyte ) ) )
269270 {
270- __Instance = Marshal . AllocHGlobal ( sizeof ( global ::Std . Allocator . __Internal ) ) ;
271+ __Instance = ( nint ) __NativeMemory . AlignedAlloc ( ( nuint ) sizeof ( global ::Std . Allocator . __Internal ) , 16 ) ;
271272 __ownsNativeInstance = true ;
272273 __RecordNativeToManagedMapping ( __Instance , this ) ;
273274 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)
290291 NativeToManagedMap . TryRemove ( __Instance , out _ ) ;
291292 DisposePartial ( disposing ) ;
292293 if ( __ownsNativeInstance )
293- Marshal . FreeHGlobal ( __Instance ) ;
294+ __NativeMemory . AlignedFree ( ( void * ) __Instance ) ;
294295 __Instance = IntPtr . Zero ;
295296 }
296297 }
@@ -439,7 +440,7 @@ internal static BasicString<_CharT, _Traits, _Allocator> __CreateInstance(global
439440
440441 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 )
441442 {
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 ) ;
443444 * ( 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 ;
444445 return ret . ToPointer ( ) ;
445446 }
@@ -465,7 +466,7 @@ public BasicString()
465466 var ___Allocator = typeof ( _Allocator ) ;
466467 if ( ___CharT . IsAssignableFrom ( typeof ( sbyte ) ) && ___Traits . IsAssignableFrom ( typeof ( global ::Std . CharTraits < sbyte > ) ) && ___Allocator . IsAssignableFrom ( typeof ( global ::Std . Allocator < sbyte > ) ) )
467468 {
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 ) ;
469470 __ownsNativeInstance = true ;
470471 __RecordNativeToManagedMapping ( __Instance , this ) ;
471472 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)
499500 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>>." ) ;
500501 }
501502 if ( __ownsNativeInstance )
502- Marshal . FreeHGlobal ( __Instance ) ;
503+ __NativeMemory . AlignedFree ( ( void * ) __Instance ) ;
503504 __Instance = IntPtr . Zero ;
504505 }
505506 }
0 commit comments