这一定很简单,但我不知道如何做到这一点:我有一个 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/