How to calculate total size of NSDictionary object?

后端 未结 4 733
野的像风
野的像风 2021-02-09 06:09

How to calculate total size of NSDictionary object? i have 3000 StudentClass objects in NSDictionary with different keys. And i want to calculate total

4条回答
  •  孤独总比滥情好
    2021-02-09 06:34

    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);
    }
    

提交回复
热议问题