c# - 优化,从内存中填充数据
问题描述
我正在尝试使用读取内存填充对象。我正在使用结构,它运行得非常快,至少看起来是这样。
float x = 0;
while (true)
{
st.Start();
List<DataChild> DataChildList = new List<DataChild>();
var Data = Algorithm.Data;
Data.ChildData.pData = IntPtr.Add(Data.ChildData.pData, 0x20);
for (int i = 0; i < Data.NumberOfObjects; i++)
{
ChildData childData = Data.ChildDatas.ReadValue(i, true);
if (childData.Render.X != x)
{
Console.WriteLine("Change detected");
x = childData.Render.X;
}
DataChildList.Add(childData)
}
Algorithm.Data.Datas = DataChildList;
st.Stop();
Console.WriteLine($"populated in {st.Elapsed.TotalMilliseconds} ms");
st.Reset();
}
}
有我的结构:
[StructLayout(LayoutKind.Explicit)]
public struct ChildData
{
[FieldOffset(0x0)]
public IntPtr BasePointer;
[FieldOffset(0x400)]
public IntPtr pRender;
public Vector3 Render
{
get
{
return M.Read<Render>(this.pRender);
}
}
}
[StructLayout(LayoutKind.Explicit)]
public struct Render
{
[FieldOffset(0x30)]
public float X;
public float posX
{
get
{
return this.X;
}
}
}
秒表说我将数据填充到0.005 ms.
当我按下一个键时,它会更改childData.Render.X
(目前列表中唯一的一个)的值。
但它会在 0.5 到 1 秒之间显示它,与循环速度相比,这似乎非常慢。
不得不说这段代码是跑到一个Thread中的。
关于为什么需要这么长时间的任何想法?谢谢!
解决方案
推荐阅读
- macos - XAMPP 7.2.10-0 - 应用程序管理器 (manager-osx) 空白按钮
- scala - 使用 NSC 编译 Scala 对象
- javascript - 如何按布尔字符串字段对javascript对象集合进行排序
- makefile - makefile:意外标记“,”附近的语法错误
- c# - How to create a C# application that opens "cmd.exe" in another window?
- python - 所有标记的seaborn散点图标记大小
- javascript - 如何将数据从一个 Marketo 实例提交到另一个?
- singularity-container - 奇点提取、编辑和重建图像
- node.js - ftpPublish 声明性管道
- android - 如何让安卓应用永不关闭?(模拟亭模式)