Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Jan 1999 16:50:06 -0800
From:      Mike Smith <mike@smith.net.au>
To:        Emmanuel Duros <Emmanuel.Duros@sophia.inria.fr>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: rules to allocate buffers in device drivers 
Message-ID:  <199901290050.QAA01181@dingo.cdrom.com>
In-Reply-To: Your message of "Thu, 28 Jan 1999 14:49:03 %2B0100." <199901281349.OAA24119@chouette.inria.fr> 

next in thread | previous in thread | raw e-mail | index | archive | help
> I am currently writing a network device driver for FreeBSD and it is
> still unclear to me how to allocate memory.
> 
> It seems that a common way of doing it is something like:
> 
> u_char  *buffer;
> buffer = malloc( SIZE, M_DEVBUF, M_NOWAIT);

Correct.

> However I have not seen something like this in a device driver:
> 
> u_char buffer[SIZE];
> 
> Is there a particular reason for not allocating buffers statically ?

Several reasons.  The simplest is that device drivers typically manage 
more than one instance of a device, so buffers and the like are 
per-instance, not per-driver.  You only get one copy of a static buffer.

> I have not found anything related to how to allocate memory in kernel
> code (definitions of malloc parameters, etc.). Do you have any pointer
> on that ?

The malloc(9) manpage covers this.

-- 
\\  Sometimes you're ahead,       \\  Mike Smith
\\  sometimes you're behind.      \\  mike@smith.net.au
\\  The race is long, and in the  \\  msmith@freebsd.org
\\  end it's only with yourself.  \\  msmith@cdrom.com



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199901290050.QAA01181>