如何找到iOS中任何对象的大小 [英] How to find the size of any object in iOS

查看:96
本文介绍了如何找到iOS中任何对象的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在优化我的应用程序,想知道对象的大小是多少,所以我也可以在日志中显示它。

I was optimizing my app and wanted to know that how much is the size of the object, so that i can also show it in log.

假设我有

   NSDictionary *temp=(NSDictionary*)[Data objectAtIndex:i];

    //data is defined in the .h file 

我知道对象temp的大小是多少。

now how will i know that how much is the size of the object temp.

我试着使用变量视图和在temp部分我发现
instance_size =(long int)30498656

I tried using the variable view and in the temp section i found the instance_size=(long int)30498656

instance_size是我的临时对象的确切大小。

Is the instance_size is the exact size of my temp object?.

/ p>

i also tried

        sizeof(temp);

但它崩溃了。
任何帮助...

but it crashed on that point. Any help...

推荐答案

编译器只知道指针,指针的大小。要查找分配对象的大小,尝试类似

The compiler knows only about the pointer, and that is why it will always return size of the pointer. To find the size of the allocated object try something like

NSLog(@"size of Object: %zd", malloc_size(myObject));

这篇关于如何找到iOS中任何对象的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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