c ++中的指针?? [英] pointers in c++ ??

查看:58
本文介绍了c ++中的指针??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一段用C ++实现FFT算法的代码,我需要将它转换成java。我试图理解

这些指针。任何有java和C ++经验的人,你能否请b / b
解释下面的代码,特别是a1 + = nFFT2行(我知道它是
增加a1变量/指针nFFT2但是如何给出每个数组的新元素

方法。任何能够将b $ b $翻译成java的人都会成为明星!


Cormac。


nFrames = 249;

nFFT2 = 128;

nChn = 25;


float * s = new float [nFrames * nFFT2]; // FFT

float * u = new float [nFrames * nChn]; // FB


// s你在这里对它们进行了操作


a1 = s;

float * a2 = u;

for(int i = 0; i< nFrames; i ++){

FBFilter(a1,a2);

a1 + = nFFT2;

a2 + = nChn;

}

解决方案

Cormac O' 'Donnell写道:



我有一段代码在c ++中实现FFT算法,我必须将它转换为java 。我正试图理解这些指针。任何有java和C ++经验的人,你能不能解释下面的代码,


我不懂Java,但是C ++,所以也许我仍然可以帮忙。

尤其是a1 + = nFFT2行(我知道它增加了a1变量/指针
nFFT2但是它如何给每个数组的方法提供了新的元素)。


a1首先指向

nFrames * nFFT2元素数组的第一个元素。增加指针意味着让它指向下一个元素

,例如添加10对它意味着让它进一步指向10

元素。所以在第一次迭代中,函数得到一个指向第一个元素的指针,第二个是指向第128个元素的指针,然后指向第256个元素。上。我猜FBFilter将永远

占用128个元素。

任何能将这个转换成java的人都会成为明星!!!
Cormac。

nFrames = 249;
nFFT2 = 128;
nChn = 25;

浮动* s =新浮点数[nFrames * nFFT2] ; // FFT
float * u = new float [nFrames * nChn]; // FB

//你在这里对它们进行了操作

a1 = s;
float * a2 = u;
for( int i = 0; i< nFrames; i ++){
FBFilter(a1,a2);
a1 + = nFFT2;
a2 + = nChn;
}




-

大小(字节):141,067

(下载Microsoft DirectX 8 SDK页面。)




" Cormac O''Donnell" <共************ @ hotmail.com>在消息中写道

news:26 ************************* @ posting.google.co m ... < blockquote class =post_quotes>

我有一段用c ++实现FFT算法的代码,我必须把它转换成java。我正试图理解这些指针。任何有java和C ++经验的人,你能不能解释下面的代码,特别是a1 + = nFFT2行(我知道它会增加a1变量/指针nFFT2但是它如何给出<每个数组都有新的FBFilter元素。任何能够将其翻译成java的人都会成为明星!

Cormac。

nFrames = 249;
nFFT2 = 128;
nChn = 25;

float * s = new float [nFrames * nFFT2]; // FFT
float * u = new float [nFrames * nChn]; // FB

//你在这里对它们进行了操作

a1 = s;
float * a2 = u;
for( int i = 0; i< nFrames; i ++){
FBFilter(a1,a2);
a1 + = nFFT2;
a2 + = nChn;
}




指针在这里使用的方式是毫无意义的(请原谅双关语。)

也许你会发现这个等价的代码更容易理解。


nFrames = 249;

nFFT2 = 128;

nChn = 25;


浮动* s = new float [nFrames * nFFT2]; // FFT

float * u = new float [nFrames * nChn]; // FB


// s你在这里对它们进行了操作


int i1 = 0;

int i2 = 0;

for(int i = 0; i< nFrames; i ++){

FBFilter(& s [i1],& u [i2} ]);

i1 + = nFFT2;

i2 + = nChn;

}


它'真的那么简单。


john


" Cormac O'Donnell" <共************ @ hotmail.com>写了



我有一段用c ++实现FFT算法的代码,我必须把它转换成java。我正试图理解这些指针。任何有java和C ++经验的人,你能不能解释下面的代码,特别是a1 + = nFFT2行(我知道它会增加a1变量/指针nFFT2但是它如何给出<每个数组都有新的FBFilter元素。任何能够将这个翻译成java的人都会成为明星!




从实际的角度来看,为什么你不打包带有JNI

接口的C ++代码?这样,你就不需要付出努力来翻译它了。你的
FFT并没有突然变成一个慢速傅里叶变换。


Claudio Puviani


hi,

I have a piece of code implementing the FFT algorithm in c++ and i
have to convert it into java. i am getting stuck trying to understand
these pointers. Anyone who has experience in java and C++, could you
please explain the code below , esp the lines a1+=nFFT2( i know it
increments the a1 variable/pointer by nFFT2 but how does this give the
methos FBFilter new elements of each array). Anyone who could
translate this to java would be a star!!!

Cormac.

nFrames = 249;
nFFT2 = 128;
nChn =25;

float* s=new float[nFrames*nFFT2]; // FFT
float* u=new float[nFrames*nChn]; // FB

// s and u have operations done on them here

a1=s;
float* a2=u;
for(int i=0;i<nFrames;i++) {
FBFilter(a1,a2);
a1+=nFFT2;
a2+=nChn;
}

解决方案

Cormac O''Donnell wrote:

hi,

I have a piece of code implementing the FFT algorithm in c++ and i
have to convert it into java. i am getting stuck trying to understand
these pointers. Anyone who has experience in java and C++, could you
please explain the code below ,
I don''t know Java, but C++, so maybe I can still help.
esp the lines a1+=nFFT2( i know it increments the a1 variable/pointer
by nFFT2 but how does this give the methos FBFilter new elements of
each array).
a1 starts with pointing to the first element of an array of
nFrames*nFFT2 elements. Incrementing a pointer means letting it point
to the next element, adding e.g. 10 to it means letting it point 10
elements further. So in the first iteration, the function gets a
pointer to the first element, in the second one, a pointer to the 128th
element, then to the 256th and so on. I guess that FBFilter will always
take a block of 128 elements.
Anyone who could translate this to java would be a star!!!

Cormac.

nFrames = 249;
nFFT2 = 128;
nChn =25;

float* s=new float[nFrames*nFFT2]; // FFT
float* u=new float[nFrames*nChn]; // FB

// s and u have operations done on them here

a1=s;
float* a2=u;
for(int i=0;i<nFrames;i++) {
FBFilter(a1,a2);
a1+=nFFT2;
a2+=nChn;
}



--
Size (bytes): 141,067
(Download page of Microsoft DirectX 8 SDK.)



"Cormac O''Donnell" <co************@hotmail.com> wrote in message
news:26*************************@posting.google.co m...

hi,

I have a piece of code implementing the FFT algorithm in c++ and i
have to convert it into java. i am getting stuck trying to understand
these pointers. Anyone who has experience in java and C++, could you
please explain the code below , esp the lines a1+=nFFT2( i know it
increments the a1 variable/pointer by nFFT2 but how does this give the
methos FBFilter new elements of each array). Anyone who could
translate this to java would be a star!!!

Cormac.

nFrames = 249;
nFFT2 = 128;
nChn =25;

float* s=new float[nFrames*nFFT2]; // FFT
float* u=new float[nFrames*nChn]; // FB

// s and u have operations done on them here

a1=s;
float* a2=u;
for(int i=0;i<nFrames;i++) {
FBFilter(a1,a2);
a1+=nFFT2;
a2+=nChn;
}



The way pointers are being used here is pretty pointless (pardon the pun).
Perhaps you''ll find this equivalent code easier to understand.

nFrames = 249;
nFFT2 = 128;
nChn =25;

float* s=new float[nFrames*nFFT2]; // FFT
float* u=new float[nFrames*nChn]; // FB

// s and u have operations done on them here

int i1=0;
int i2=0;
for(int i=0;i<nFrames;i++) {
FBFilter(&s[i1],&u[i2]);
i1+=nFFT2;
i2+=nChn;
}

It''s really that simple.

john


"Cormac O''Donnell" <co************@hotmail.com> wrote

hi,

I have a piece of code implementing the FFT algorithm in c++ and i
have to convert it into java. i am getting stuck trying to understand
these pointers. Anyone who has experience in java and C++, could you
please explain the code below , esp the lines a1+=nFFT2( i know it
increments the a1 variable/pointer by nFFT2 but how does this give the
methos FBFilter new elements of each array). Anyone who could
translate this to java would be a star!!!



From a practical point of view, why don''t you just wrap the C++ code with a JNI
interface? That way, you don''t need to put effort into translating it AND your
FFT doesn''t suddenly become a S L O W Fourier Transform.

Claudio Puviani


这篇关于c ++中的指针??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆