在C#中,我有一个简单的3D矢量类.
static void Main(string[] args)
{
Vector3D a, b;
a = new Vector3D(0, 5, 10);
b = new Vector3D(0, 0, 0);
b = a;
a.x = 10;
Console.WriteLine("vector a=" + a.ToString());
Console.WriteLine("vector b=" + b.ToString());
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)
输出是,
矢量a = 10,5,10
矢量b = 10,5,10
在我将斧头改为10之前我分配了一个.所以我在期待
矢量a = 10,5,10
矢量b = 0,5,10
根据我的理解=运算符像指针一样分配对象的引用?在C#中我不能超载=运算符.
我必须手动分配每个属性吗?
我如何在OpenCL中定义函数?我试着为每个函数构建一个程序.它没有奏效.
float AddVectors(float a, float b)
{
return a + b;
}
kernel void VectorAdd(
global read_only float* a,
global read_only float* b,
global write_only float* c )
{
int index = get_global_id(0);
//c[index] = a[index] + b[index];
c[index] = AddVectors(a[index], b[index]);
}
Run Code Online (Sandbox Code Playgroud) 我正在编写一个输出模块来显示我在另一个程序上的数据.
如果检查代码,我将点坐标添加到字符串,然后将此字符串作为TextNode添加到另一个元素.问题是点数可以超过500000
是否有更好的方法将大量文本写入xml或者这样可以吗?
XMLElement points = doc.CreateElement("VTK", "DataArray");
string str = "";
for (int i = 0; i < sim.NumberOfParticles; i++)
{
str += sim.pPosX[i].ToString() + " " + sim.pPosY[i] + " " + sim.pPosZ[i] + "\n"
}
XmlText coordinates = doc.CreateTextNode(str);
points.AppendChild(coordinates);
Run Code Online (Sandbox Code Playgroud)