问题描述
我已经开发了自己的复制功能来处理我自己的动态内存
结构。它有效,但我觉得它效率不高。必须有
更快的方式来复制数据。在我的一些例程中我开发了复制函数被调用数百次,其中
非常大的数据结构。这可能需要一些时间....
如果您无法通过代码判断数据结构是存储复数的
矩阵。
附上的是代码。
struct complexMatrix
{
float r ;
浮动i;
};
typedef complexMatrix ** ComplexMatrix;
typedef complexMatrix复杂;
ComplexMatrix Cmxcopy(ComplexMatrix mat,int rows,int cols)
{
int i;
int j;
ComplexMatrix temp;
temp = CmxAlloc(rows,cols);
for(i = 0; i< rows; i ++)
for(j = 0; j< cols; j ++)
{
temp [i] [j] .r = mat [0] [0] .r;
temp [i] [j] .i = mat [0] [0] .i;
}
返回临时;
}
所有建议,评论,电子邮件,传真,邮寄和备忘录欢迎。
I have developed my own copy function for coping my own dynamic memory
structure. It works, but I feel its not too efficient. There must be
a quicker way to copy the data. In some of the routines I have
developed the copy function gets called several hundreds of times, with
very large data structures. This can take some time....
If you can''t tell by the code the data structure is a matrix for
storing complex numbers.
Attached is the code.
struct complexMatrix
{
float r;
float i;
};
typedef complexMatrix** ComplexMatrix;
typedef complexMatrix Complex;
ComplexMatrix Cmxcopy(ComplexMatrix mat, int rows, int cols)
{
int i;
int j;
ComplexMatrix temp;
temp=CmxAlloc(rows,cols);
for(i=0;i<rows;i++)
for(j=0;j<cols;j++)
{
temp[i][j].r=mat[0][0].r;
temp[i][j].i=mat[0][0].i;
}
return temp;
}
All suggesting, comments, emails, faxes, post-its and memos welcome.
推荐答案
V
V
Fra请注意。 ''ComplexMatrix''指向''complexMatrix''结构的指针
。没有析构函数。
Frank, please pay attention. ''ComplexMatrix'' is a pointer to a pointer
to ''complexMatrix'' struct. There is no destructor.
这篇关于帮助找到复制动态内存的有效方法!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!