diff --git a/Source/Editor/Tools/Terrain/Undo/EditTerrainMapAction.cs b/Source/Editor/Tools/Terrain/Undo/EditTerrainMapAction.cs index f9a48d659..6a90bc61d 100644 --- a/Source/Editor/Tools/Terrain/Undo/EditTerrainMapAction.cs +++ b/Source/Editor/Tools/Terrain/Undo/EditTerrainMapAction.cs @@ -124,7 +124,7 @@ namespace FlaxEditor.Tools.Terrain.Undo { var data = Marshal.AllocHGlobal(_heightmapDataSize); var source = GetData(ref patchCoord, tag); - Utils.MemoryCopy(source, data, _heightmapDataSize); + Utils.MemoryCopy(data, source, (ulong)_heightmapDataSize); _patches.Add(new PatchData { PatchCoord = patchCoord, @@ -150,7 +150,7 @@ namespace FlaxEditor.Tools.Terrain.Undo var data = Marshal.AllocHGlobal(_heightmapDataSize); var source = GetData(ref patch.PatchCoord, patch.Tag); - Utils.MemoryCopy(source, data, _heightmapDataSize); + Utils.MemoryCopy(data, source, (ulong)_heightmapDataSize); patch.After = data; _patches[i] = patch; } diff --git a/Source/Engine/Animations/AnimationGraph.cs b/Source/Engine/Animations/AnimationGraph.cs index 1a5c9133d..0bdc95708 100644 --- a/Source/Engine/Animations/AnimationGraph.cs +++ b/Source/Engine/Animations/AnimationGraph.cs @@ -193,7 +193,7 @@ namespace FlaxEngine throw new ArgumentNullException(nameof(destination)); destination->NodesCount = source->NodesCount; destination->Unused = source->Unused; - Utils.MemoryCopy(new IntPtr(source->Nodes), new IntPtr(destination->Nodes), source->NodesCount * sizeof(Transform)); + Utils.MemoryCopy(new IntPtr(destination->Nodes), new IntPtr(source->Nodes), (ulong)(source->NodesCount * sizeof(Transform))); destination->RootMotionTranslation = source->RootMotionTranslation; destination->RootMotionRotation = source->RootMotionRotation; destination->Position = source->Position; diff --git a/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp b/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp index 050fbca3a..814b20dcd 100644 --- a/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp +++ b/Source/Engine/Scripting/InternalCalls/EngineInternalCalls.cpp @@ -8,11 +8,6 @@ namespace UtilsInternal { - void MemoryCopy(void* source, void* destination, int32 length) - { - Platform::MemoryCopy(destination, source, length); - } - MonoObject* ExtractArrayFromList(MonoObject* obj) { auto klass = mono_object_get_class(obj); @@ -78,7 +73,9 @@ namespace FlaxLogWriterInternal void registerFlaxEngineInternalCalls() { AnimGraphExecutor::initRuntime(); - ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryCopy", &UtilsInternal::MemoryCopy); + ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryCopy", &Platform::MemoryCopy); + ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryClear", &Platform::MemoryClear); + ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryCompare", &Platform::MemoryCompare); ADD_INTERNAL_CALL("FlaxEngine.Utils::Internal_ExtractArrayFromList", &UtilsInternal::ExtractArrayFromList); ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_LogWrite", &DebugLogHandlerInternal::LogWrite); ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_Log", &DebugLogHandlerInternal::Log); diff --git a/Source/Engine/Scripting/ManagedCLR/MCore.Mono.cpp b/Source/Engine/Scripting/ManagedCLR/MCore.Mono.cpp index 64abca055..5e4703d2d 100644 --- a/Source/Engine/Scripting/ManagedCLR/MCore.Mono.cpp +++ b/Source/Engine/Scripting/ManagedCLR/MCore.Mono.cpp @@ -169,18 +169,20 @@ void OnGCAllocation(MonoProfiler* profiler, MonoObject* obj) //LOG(Info, "GC new: {0}.{1} ({2} bytes)", name_space, name, size); #if 0 - if (ProfilerCPU::IsProfilingCurrentThread()) - { - static int details = 0; - if (details) - { - StackWalkDataResult stackTrace; - stackTrace.Buffer.SetCapacity(1024); - mono_stack_walk(&OnStackWalk, &stackTrace); + if (ProfilerCPU::IsProfilingCurrentThread()) + { + static int details = 0; + if (details) + { + StackWalkDataResult stackTrace; + stackTrace.Buffer.SetCapacity(1024); + mono_stack_walk(&OnStackWalk, &stackTrace); - LOG(Info, "GC new: {0}.{1} ({2} bytes). Stack Trace:\n{3}", String(name_space), String(name), size, stackTrace.Buffer.ToStringView()); - } - } + const auto msg = String::Format(TEXT("GC new: {0}.{1} ({2} bytes). Stack Trace:\n{3}"), String(name_space), String(name), size, stackTrace.Buffer.ToStringView()); + Platform::Log(*msg); + //LOG_STR(Info, msg); + } + } #endif #if COMPILE_WITH_PROFILER diff --git a/Source/Engine/Serialization/UnmanagedMemoryStream.cs b/Source/Engine/Serialization/UnmanagedMemoryStream.cs index 12b7c4634..8e0067839 100644 --- a/Source/Engine/Serialization/UnmanagedMemoryStream.cs +++ b/Source/Engine/Serialization/UnmanagedMemoryStream.cs @@ -84,7 +84,7 @@ namespace FlaxEngine.Json if (toRead <= 0) return 0; fixed (byte* bufferPtr = buffer) - Utils.MemoryCopy(new IntPtr(_ptr + _pos), new IntPtr(bufferPtr), toRead); + Utils.MemoryCopy(new IntPtr(bufferPtr), new IntPtr(_ptr + _pos), (ulong)toRead); _pos += toRead; return toRead; } @@ -135,7 +135,7 @@ namespace FlaxEngine.Json if (newPos > _length) _length = newPos; fixed (byte* bufferPtr = buffer) - Utils.MemoryCopy(new IntPtr(_pos + _pos), new IntPtr(bufferPtr), count); + Utils.MemoryCopy(new IntPtr(bufferPtr), new IntPtr(_pos + _pos), (ulong)count); _pos = newPos; } diff --git a/Source/Engine/Utilities/Utils.cs b/Source/Engine/Utilities/Utils.cs index 52b800f90..f0c9d4452 100644 --- a/Source/Engine/Utilities/Utils.cs +++ b/Source/Engine/Utilities/Utils.cs @@ -17,14 +17,45 @@ namespace FlaxEngine /// /// Copies data from one memory location to another using an unmanaged memory pointers. /// - /// - /// Uses low-level memcpy call. - /// + /// Uses low-level platform impl. + /// The source location. + /// The destination location. + /// The length (amount of bytes to copy). + [Obsolete("Use MemoryCopy with long length and source/destination swapped to match C++ API.")] + public static void MemoryCopy(IntPtr source, IntPtr destination, int length) + { + // [Deprecated on 30.05.2021, expires on 30.05.2022] + MemoryCopy(destination, source, (ulong)length); + } + + /// + /// Copies data from one memory location to another using an unmanaged memory pointers. + /// + /// Uses low-level platform impl. /// The source location. /// The destination location. /// The length (amount of bytes to copy). [MethodImpl(MethodImplOptions.InternalCall)] - public static extern void MemoryCopy(IntPtr source, IntPtr destination, int length); + public static extern void MemoryCopy(IntPtr destination, IntPtr source, ulong length); + + /// + /// Clears the memory region with zeros. + /// + /// Uses low-level platform impl. + /// Destination memory address + /// Size of the memory to clear in bytes + [MethodImpl(MethodImplOptions.InternalCall)] + public static extern void MemoryClear(IntPtr dst, ulong size); + + /// + /// Compares two blocks of the memory. + /// + /// Uses low-level platform impl. + /// The first buffer address. + /// The second buffer address. + /// Size of the memory to compare in bytes. + [MethodImpl(MethodImplOptions.InternalCall)] + public static extern int MemoryCompare(IntPtr buf1, IntPtr buf2, ulong size); /// /// Rounds the floating point value up to 1 decimal place.