I'm about to start writing an iOS game and I'm going to use mainly C++/C for the core gameplay logic.

I really like pre-allocating everything in the game and try to avoid any dynamic allocations as much as possible. With my own C++/C code it's not a big deal. However there are some ObjC libraries which I'd like to re-use and I'm not sure how to inject my custom memory allocator to Cocoa based classes.

Is there any central 'inject point' in Cocoa where I can do that?

  • \$\begingroup\$ Why are you trying to inject your custom memory allocator into other libraries? This sounds like obsessive pre-optimization. \$\endgroup\$ – thedaian Aug 26 '11 at 13:39
  • \$\begingroup\$ I'd like to know exactly how much memory is utilized and in what components. \$\endgroup\$ – pachanga Aug 26 '11 at 13:46
  • 4
    \$\begingroup\$ @thedaian: On the contrary, injecting memory allocators is a key part of measurement, which is exactly how you optimize properly. \$\endgroup\$ – user744 Aug 26 '11 at 14:33

This is all highly theoretical but you may be able to use categories (Mac Developer Tips) to override NSObjects (Apple Developer) alloc and dealloc methods.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.