Skip to content

Commit

Permalink
Align memory alloc.
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao committed Oct 29, 2024
1 parent eda3dab commit 05eb5f3
Show file tree
Hide file tree
Showing 11 changed files with 4,352 additions and 4,341 deletions.
1,719 changes: 860 additions & 859 deletions src/CppParser/Bindings/CSharp/arm64-apple-darwin/CppSharp.CppParser.cs

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions src/CppParser/Bindings/CSharp/arm64-apple-darwin/Std.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using __NativeMemory = global::System.Runtime.InteropServices.NativeMemory;
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
using __IntPtr = global::System.IntPtr;

Expand Down Expand Up @@ -110,7 +111,7 @@ internal static CharTraits<_CharT> __CreateInstance(global::Std.CharTraits.__Int

private static void* __CopyValue(global::Std.CharTraits.__Internal native)
{
var ret = Marshal.AllocHGlobal(sizeof(global::Std.CharTraits.__Internal));
var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.CharTraits.__Internal), 16);
*(global::Std.CharTraits.__Internal*) ret = native;
return ret.ToPointer();
}
Expand Down Expand Up @@ -143,7 +144,7 @@ internal protected virtual void Dispose(bool disposing, bool callNativeDtor)
NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing);
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
__NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero;
}
}
Expand Down Expand Up @@ -243,7 +244,7 @@ internal static Allocator<_Tp> __CreateInstance(global::Std.Allocator.__Internal

private static void* __CopyValue(global::Std.Allocator.__Internal native)
{
var ret = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal));
var ret = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
*(global::Std.Allocator.__Internal*) ret = native;
return ret.ToPointer();
}
Expand All @@ -267,7 +268,7 @@ public Allocator()
var ___Tp = typeof(_Tp);
if (___Tp.IsAssignableFrom(typeof(sbyte)))
{
__Instance = Marshal.AllocHGlobal(sizeof(global::Std.Allocator.__Internal));
__Instance = (nint)__NativeMemory.AlignedAlloc((nuint)sizeof(global::Std.Allocator.__Internal), 16);
__ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this);
global::Std.Allocator.__Internal.ctorc__N_std_N___1_S_allocator__C(__Instance);
Expand All @@ -290,7 +291,7 @@ internal protected virtual void Dispose(bool disposing, bool callNativeDtor)
NativeToManagedMap.TryRemove(__Instance, out _);
DisposePartial(disposing);
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
__NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero;
}
}
Expand Down Expand Up @@ -439,7 +440,7 @@ internal static BasicString<_CharT, _Traits, _Allocator> __CreateInstance(global

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)
{
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));
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);
*(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;
return ret.ToPointer();
}
Expand All @@ -465,7 +466,7 @@ public BasicString()
var ___Allocator = typeof(_Allocator);
if (___CharT.IsAssignableFrom(typeof(sbyte)) && ___Traits.IsAssignableFrom(typeof(global::Std.CharTraits<sbyte>)) && ___Allocator.IsAssignableFrom(typeof(global::Std.Allocator<sbyte>)))
{
__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));
__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);
__ownsNativeInstance = true;
__RecordNativeToManagedMapping(__Instance, this);
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);
Expand Down Expand Up @@ -499,7 +500,7 @@ internal protected virtual void Dispose(bool disposing, bool callNativeDtor)
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>>.");
}
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
__NativeMemory.AlignedFree((void*)__Instance);
__Instance = IntPtr.Zero;
}
}
Expand Down
Loading

0 comments on commit 05eb5f3

Please sign in to comment.