objective-c - 我很困惑。我的代码有什么问题?关于 malloc 和函数将指针传递给指针

标签 objective-c ios pointers malloc

<分区>

- (void) rgbMatrix:(UIImage *)i toRGB:(uint32_t **)rgbArray{
    int m_width = i.size.width;  
    int m_height = i.size.height;  
    *rgbArray = (uint32_t *) malloc(m_width * m_height * sizeof(uint32_t));  
}

uint32_t *rgbArray = NULL;
[self rgbMatrix:image toRGB:&rgbArray];

有人可以帮忙吗?这不行。在 objective-c 中不支持使用 malloc 的方式吗?

最佳答案

您似乎正确地通过引用传递了指针。

唯一可能存在问题的地方是将 rgbArray 声明为 null(我认为只写 uint32_t *rgbArray; 更安全)。另一个问题是释放内存

关于objective-c - 我很困惑。我的代码有什么问题?关于 malloc 和函数将指针传递给指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9680312/

相关文章:

pointers - 运行时错误: invalid memory address or nil pointer dereference in public pointer

c - 错误 : making pointer from integer in C

c - 函数中 C 中的指针怪异行为

iphone - iOS 7 中的 UITabBar 色调

iphone - 从后台更新 plist

ios - 警告 :-Presenting view controllers on detached view controllers is discouraged

ios - 从 imageview 点击手势获取索引或标签值

iphone - 第一次向 NSMutableArray 添加对象

iphone - iOS自定义表格 View 单元格标签调整大小损坏

ios - 用户登录时 PopToRootViewController 不更新 collectionview