Search code examples
iosobjective-ccocoacgpointnsvalue

Performance - structs in NSValue vs container object


In a situation where I need to save all data members in a NSDictionary, does it make more sense to put structs (custom types, or even scalars i.e. CGPoint) in my own wrapper (not NSValue), so I can avoid the overhead of encoding/decoding it every time I get or set the member?

For large structs (16 floats) the savings is IMO significant. But even with a CGPoint I'd be saving 4 bytes of copying plus encoding/decoding time.


Solution

  • Why not just measure it for your specific case? That is the only really reliable way to find it out.

    If both options are not sufficient you could look into CFDictionary with pointers to plain structs by setting the value callbacks accordingly or take a C++ std::map/std::tr1::unordered_map for a spin (if you don't mind mixing in C++ that is).