Subject: Re: Many thanks and a new question...
To: Eric Fischer <eric@fudge.uchicago.edu>
From: Chris G. Demetriou <cgd@pa.dec.com>
List: tech-kern
Date: 07/21/1997 20:36:38
> > MALLOC is meant to be used in critical paths, where you don't want the
> > extra overhead that a function call to malloc() might cause.
> 
> Are interrupt handlers considered critical enough to use MALLOC()
> instead of malloc()?  Or even so critical that I should be avoiding
> allocating memory at all?

They certainly could be a good choice, yes.  However, it's generally a
good idea to profile and/or examine code usage _then_ optimize.  8-)

Depending on what your driver does at interrupt time, it may very well
make sense to allocate buffer or buffers outside of interrupt time,
allocating them at interrupt time only if you happen to run out.
However, you can't really know that before you've examined the code
and how it's being used.

One word of caution, that i mentioned before: it usually only makes
sense to use MALLOC if you're allocating a size-fixed-at-compile-time
object.  if you're allocating based on the contents of a variable,
you'll get a lot more inline code, and probably won't save any
significant amount of time.  (If you're allocating a variable-sized
object, the MALLOC macro can't optimize out much of the
bucket-selection logic.)

Note also that if you're compiling with DIAGNOSTIC or KMEMSTATS
enabled, MALLOC() and malloc() end up doing exactly the same thing,
anyway.  8-)



chris