How to find the size of any object in iOS?(如何在 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?
我尝试使用变量视图并在我发现的临时部分中:
I tried using the variable view and in the temp section I found:
instance_size=(long int)30498656
instance_size
是我的临时对象的确切大小吗?
Is the instance_size
the exact size of my temp object?.
我也试过
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 中找到任何对象的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS 中找到任何对象的大小?


基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01