Re: Garbage collector in an audio unit
Re: Garbage collector in an audio unit
- Subject: Re: Garbage collector in an audio unit
- From: Ian Kemmish <email@hidden>
- Date: Mon, 24 May 2010 20:31:43 +0100
On 23 May 2010, at 16:17, Paul Fultz <email@hidden> wrote:
Now I have a framework for audio processing that uses Hans-boehm
garbage collector, and of course I dont do any memory allocations
during the process call. I was wondering if it was possible to use
this in an audio unit since it is ran inside the host.
The usual trick for writing memory managers (garbage collecting or
otherwise) which play nice is to write them so that they stay inside
their own memory arena. When the memory manager needs more memory, it
just calls malloc() (or valloc() to give you page-aligned memory) to
allocate a chunk of memory, usually from several OS pages to several
hundred OS pages. Your memory manager then slices this chunk up into
smaller things as and when it is called upon to do allocate objects.
When garbage collecting, just make sure your garbage collector never
touches any memory the memory manager did not get from malloc()/
valloc().
You may have noticed that Mach provides a way to do allocations within
"zones", underneath the BSD-style malloc() calls. I tried this once
in NextStep - it wasn't really worth the bother, so I'd recommend
sticking with malloc() and friends to feed your memory manager.
The Hans-boehm gc requires an initialize command at the beginning of
the program on the mac. This may not be possible in an audio unit.
Does anyone have experience with this?
Just have a flag which says whether your memory manager has allocated
anything yet. The first time you call your thing-allocation routine,
that flag won't be set, so you should initialise your memory manager
before proceeding. The cost of a single compare per allocation should
be acceptable in most situations. Especially compared to the cost of
a garbage sweep:-) Since only your own code is ever going to be
allocating stuff using your memory manager, and since being an audio
unit it's only ever going to do that really late in the day, the
question of dealing with how Mac OS starts tasks up shouldn't even
arise.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
Ian Kemmish 18 Durham Close, Biggleswade, Beds
SG18 8HZ
email@hidden Tel: +44 1767 601361 Mob: +44 7952
854387
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden