在标题中是否可以将多个数组连接在一起而无需复制并仅使用指针?我花费了大量的计算时间将较小的数组复制到较大的数组中.注意我不能使用向量,因为umfpack(一些矩阵求解库)不允许我或我不知道如何.
举个例子:
int n = 5;
// dynamically allocate array with use of pointer
int *a = new int[n];
// define array pointed by *a as [1 2 3 4 5]
for(int i=0;i<n;i++) {
a[i]=i+1;
}
// pointer to array of pointers ??? --> this does not work
int *large_a = new int[4];
for(int i=0;i<4;i++) {
large_a[i] = a;
}
Run Code Online (Sandbox Code Playgroud)
注意:我已经知道了一个简单的解决方案,只是迭代地将它们复制到一个新的大型数组中,但很高兴知道是否不需要复制在整个程序期间存储的重复块.我正处于学习曲线中.
感谢大家阅读