• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Avoiding memory fragmentation was Re: Cross platform Cocoa/Obj-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Avoiding memory fragmentation was Re: Cross platform Cocoa/Obj-C


  • Subject: Avoiding memory fragmentation was Re: Cross platform Cocoa/Obj-C
  • From: Brian Hook <email@hidden>
  • Date: Sat, 22 Dec 2001 11:18:32 -0800

At 10:09 AM 12/22/2001 -0500, Simson Garfinkel wrote:
implement your own memory allocation scheme. However, it is my experience
that many applications which appear to require dynamic memory allocation
with compaction can be redesigned so that they don't. When they are
redesigned, they frequently run faster.

Okay, I'll bite: how would I do this in Obj-C? In C/C++, I typically have fixed size heaps for certain objects. For example, in a game I might have a global table of entities:

Entity g_aEntities[ MAX_ENTITIES ];

With a routine that grabs one whenever I need it:

Entity *
Entity::s_createEntity( void )
{
return sm_findFreeEntity(); //searches g_aEntities for a free entity
}

This is technically less efficient, but makes debugging much easier and gives way more predictable (and capped) memory consumption.

I'm unclear how I would do this in Obj-C (I'm still a newbie), since all the code I see uses the alloc(withZone)/init paradigm. If I could do use a pattern in Obj-C where dynamic memory allocation was greatly minimized without losing the nice aspects of Obj-C, I'd be a happy camper.

The specific app I'm working on is a server/simulation app that is going to have very long run times (weeks) and likely will do hundreds of thousands of allocations of many different sizes and in varying orders.

Brian


References: 
 >Re: Cross platform Cocoa/Obj-C (From: "Simson Garfinkel" <email@hidden>)

  • Prev by Date: Re: Cross platform Cocoa/Obj-C
  • Next by Date: Re: TCP/IP Connections
  • Previous by thread: Re: Cross platform Cocoa/Obj-C
  • Next by thread: Re: Cross platform Cocoa/Obj-C
  • Index(es):
    • Date
    • Thread