objective-c - 在 Objective C 中声明和使用 C 函数

标签 objective-c c

这一定很简单,但我不知道如何做到这一点:我有一个 C 函数来监视当前的内存使用情况:

natural_t report_memory(void) {
    struct task_basic_info info;
    mach_msg_type_number_t size = sizeof(info);
    kern_return_t kerr = task_info(mach_task_self(),
                               TASK_BASIC_INFO,
                               (task_info_t)&info,
                               &size);
    if( kerr == KERN_SUCCESS ) {
        return info.resident_size;
    } else {
        NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
        return 0;
    }
}

现在,我想使用它。我如何在 .h 中声明它?
我在客观 c 方法中尝试了(对我来说)显而易见的:
natural_t report_memory(void);

在代码中的某处调用它:
NSLog(@"Memory used: %u", rvC.report_memory());

编译器提示 error: called object is not a function .因此,我认为,声明在某种程度上是错误的。我尝试了几种选择,但我能得到的最好的是运行时错误......
如何解决这个问题?

最佳答案

rvC.report_memory()

应该替换为
report_memory()

因为它是一个C函数。

关于objective-c - 在 Objective C 中声明和使用 C 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4761676/

相关文章:

objective-c - 什么更有效率 : loading and adding a nib or creating the custom controls programmatically?

ios - 如何在 crittercism 中使用崩溃日志找到崩溃?

c - float 包含超过 4byte

c - 导航功能将其所有输出打印两次

ios - 为什么在调用 [super prepareForReuse] 后删除了自定义 UITableViewCell 上 UIImageView 中的 'animations' 属性?

objective-c - 实现音量控制

iphone - objective-c : How to highlight the first cell in table view when view loads?

c - CUDA矩阵水平翻转中的无效参数

c - 为二维数组分配内存

c - 在 SPI STM32 中读取 Rx 缓冲区的问题