Match C++ managed memory alloc with C# for scripting
This commit is contained in:
@@ -1098,6 +1098,18 @@ namespace FlaxEngine
|
||||
nativeLibraryPaths[moduleName] = modulePath;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static void* AllocMemory(int size)
|
||||
{
|
||||
return NativeMemory.AlignedAlloc((UIntPtr)size, 16);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
internal static void FreeMemory(void* ptr)
|
||||
{
|
||||
NativeMemory.AlignedFree(ptr);
|
||||
}
|
||||
|
||||
internal static void* NativeAlloc(int byteCount)
|
||||
{
|
||||
return NativeMemory.AlignedAlloc((UIntPtr)byteCount, 16);
|
||||
|
||||
@@ -129,14 +129,18 @@ void CoreCLR::RegisterNativeLibrary(const char* moduleName, const char* modulePa
|
||||
CoreCLR::CallStaticMethod<void, const char*, const char*>(RegisterNativeLibraryPtr, moduleName, modulePath);
|
||||
}
|
||||
|
||||
void* CoreCLR::Allocate(int size)
|
||||
void* CoreCLR::Allocate(int32 size)
|
||||
{
|
||||
return Platform::Allocate(size, 16);
|
||||
static void* AllocMemoryPtr = CoreCLR::GetStaticMethodPointer(TEXT("AllocMemory"));
|
||||
return CoreCLR::CallStaticMethod<void*, int32>(AllocMemoryPtr, size);
|
||||
}
|
||||
|
||||
void CoreCLR::Free(void* ptr)
|
||||
{
|
||||
Platform::Free(ptr);
|
||||
if (!ptr)
|
||||
return;
|
||||
static void* FreeMemoryPtr = CoreCLR::GetStaticMethodPointer(TEXT("FreeMemory"));
|
||||
CoreCLR::CallStaticMethod<void, void*>(FreeMemoryPtr, ptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
static void RegisterNativeLibrary(const char* moduleName, const char* modulePath);
|
||||
|
||||
static const char* GetClassFullname(void* klass);
|
||||
static void* Allocate(int size);
|
||||
static void* Allocate(int32 size);
|
||||
static void Free(void* ptr);
|
||||
static MGCHandle NewGCHandle(void* obj, bool pinned);
|
||||
static MGCHandle NewGCHandleWeakref(void* obj, bool track_resurrection);
|
||||
|
||||
@@ -1450,8 +1450,7 @@ MONO_API MONO_RT_EXTERNAL_ONLY MonoMethod* mono_class_get_method_from_name(MonoC
|
||||
|
||||
MONO_API void mono_free(void* ptr)
|
||||
{
|
||||
if (ptr != nullptr)
|
||||
CoreCLR::Free(ptr);
|
||||
CoreCLR::Free(ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user