C / Objective C 指针声明
我有一个需要 float**
类型参数的函数,但我不知道如何声明和初始化该变量。
有人可以给我任何建议吗?更好的是,它是什么类型的变量?我已经研究了好几天了,所有搜索结果都是空的。
谢谢
编辑
这是有问题的函数
- (OSStatus)getBuffersInner:(float**)buffers numberOfBuffers:(int)chnls samples:(int)samples
{
int i, j ;
UInt32 frames ;
// zero out requested buffers if client needs more channels than exist in the channel map
for ( i = numberOfMappedChannels; i < chnls; i++ ) memset( buffers[i], 0, samples*sizeof( float ) ) ;
// place buffer pointers into bufferList, following the channelMap
for ( i = 0; i < fileDescriptor.mChannelsPerFrame; i++ ) {
j = inverseChannelMap[i] ;
resampledBufferList.list.mBuffers[i].mData = ( j < 0 || j >= chnls ) ? zeros : buffers[j] ;
}
frames = samples ;
return ExtAudioFileRead( audioFileRef, &frames, &resampledBufferList.list ) ;
}
I have a function that expects a parameter of type float**
, but I do not know how to declare and initialize this variable.
Can anyone give me any advice on this? Better yet, what type of variable is it? I have been looking into it for days now and any search results comes up empty.
Thanks
EDIT
Here is the function in question
- (OSStatus)getBuffersInner:(float**)buffers numberOfBuffers:(int)chnls samples:(int)samples
{
int i, j ;
UInt32 frames ;
// zero out requested buffers if client needs more channels than exist in the channel map
for ( i = numberOfMappedChannels; i < chnls; i++ ) memset( buffers[i], 0, samples*sizeof( float ) ) ;
// place buffer pointers into bufferList, following the channelMap
for ( i = 0; i < fileDescriptor.mChannelsPerFrame; i++ ) {
j = inverseChannelMap[i] ;
resampledBufferList.list.mBuffers[i].mData = ( j < 0 || j >= chnls ) ? zeros : buffers[j] ;
}
frames = samples ;
return ExtAudioFileRead( audioFileRef, &frames, &resampledBufferList.list ) ;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是一个指针到指针。以下是示例用法:
您可能需要查看此。
This is a pointer-to-pointer. Here is a sample usage:
You may want to look into this.
指针可以用于多种用途。在这种情况下,它可能用于动态内存和更改函数中的(指针)值。
通常情况下,它可能是:
请注意,将参数作为要更改的指针传递比 C++ 更具 C 风格,尽管为了清晰起见,有些人更喜欢它而不是传递引用。
在 C++ 中也不鼓励对动态内存使用原始指针。
Pointers can be used for several things. In this case it is probably used for dynamic memory and for changing a (pointer-)value in the function.
So typically, it could be:
Mind you that passing parameters as pointers to change is more C-style than C++, although some prefer it over passing references for clarity.
Using raw pointers for dynamic memory is also discouraged in C++.
只是一个“指向浮动指针的指针”:只需将句子拆开即可。
Just a "pointer to a pointer to float": just break up the sentence.
在您的代码中,
float** buffers
保存一个指向float*
的指针向量。例如,在普通 C 中:In your code,
float** buffers
holds a vector of pointers tofloat*
. For example, in plain C:从您显示的代码来看,该函数似乎正在使用
float**
作为指向数组 [chnls] 的指针
样本`]。在这种情况下,最好的解决方案可能是使用浮动[
类似于:
并将
&args[0]
传递给函数。(如果这看起来很复杂,事实确实如此。这就是我们付出的代价
必须与 C 接口。如果目标函数是 C++ 语言,则有
比使用
float**
更好的解决方案。)From the code you show, it looks like the function is using the
float**
as a pointer to an array[chnls] of pointers to
samples`]. In this case, the best solution is probably to usefloats[
something like:
And pass
&args[0]
to the function.(And if this seems complicated, it is. That's the price we pay for
having to interface C. If the target function is in C++, there are
much, much better solutions than using
float**
.)它是 float[n][m] 矩阵。像 int main(int argc, char **argv) 之类的东西,其中 argv 是一个“字符串”数组,一个 char 数组的数组。
It is float[n][m] matrix. Something like int main(int argc, char **argv), where argv is an array of 'strings', an array of arrays of char.