如何计算NSDictionary对象的总大小? [英] How to calculate total size of NSDictionary object?

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

问题描述

如何计算 NSDictionary 对象的总大小?
我在 NSDictionary 中有3000个不同键的StudentClass对象。我想以KB为单位计算字典的总大小。
我使用 malloc_size()但它总是返回24( NSDictionary 包含1个对象或3000个对象)
sizeof()也总是返回相同。

How to calculate total size of NSDictionary object? i have 3000 StudentClass objects in NSDictionary with different keys. And i want to calculate total size of dictionary in KB. I used malloc_size() but it always return 24 (NSDictionary contain either 1 object or 3000 object) sizeof() also returns always same.

推荐答案

您可以尝试在数组中获取Dictionary的所有键,然后迭代数组以查找大小,它可能会为您提供字典中键的总大小。

You could try to get all the keys of the Dictionary in an array and then iterate the array to find the size, it might give you the total size of the keys inside the dictionary.

NSArray *keysArray = [yourDictionary allValues];
id obj = nil;
int totalSize = 0;

for(obj in keysArray)
{
    totalSize += malloc_size(obj);
}

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

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