iphone - Byte size of an NSDictionary -
this may sound stupid question, how can size in bytes of nsdictionary? can convert nsdata, , length of that?
help!
you should more why care size of dictionary in bytes, because answer might different depending.
in general, "size" of nsdictionary's footprint in memory not can see or care about. abstracts storage mechanism programmer, , uses form of overhead beyond actual data it's storing.
you can, however, serialize dictionary nsdata. if contents of dictionary "primitive" types nsnumber, nsstring, nsarray, nsdata, nsdictionary, can use nspropertylistserialization class turn binary property list, compact byte representation of contents can get:
nsdictionary * mydictionary = /* ... */; nsdata * data = [nspropertylistserialization datafrompropertylist:mydictionary format:nspropertylistbinaryformat_v1_0 errordescription:null]; nslog(@"size: %d", [data length]);
if contains other custom objects, use nskeyedarchiver archive nsdata, larger , requires cooperation of custom classes.
Comments
Post a Comment