From owner-freebsd-hackers Thu Jan 28 16:54:03 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA20433 for freebsd-hackers-outgoing; Thu, 28 Jan 1999 16:54:03 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from dingo.cdrom.com (dingo.cdrom.com [204.216.28.145]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA20427 for ; Thu, 28 Jan 1999 16:54:01 -0800 (PST) (envelope-from mike@dingo.cdrom.com) Received: from dingo.cdrom.com (localhost.cdrom.com [127.0.0.1]) by dingo.cdrom.com (8.9.1/8.8.8) with ESMTP id QAA01181; Thu, 28 Jan 1999 16:50:06 -0800 (PST) (envelope-from mike@dingo.cdrom.com) Message-Id: <199901290050.QAA01181@dingo.cdrom.com> X-Mailer: exmh version 2.0.2 2/24/98 To: Emmanuel Duros cc: freebsd-hackers@FreeBSD.ORG Subject: Re: rules to allocate buffers in device drivers In-reply-to: Your message of "Thu, 28 Jan 1999 14:49:03 +0100." <199901281349.OAA24119@chouette.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 28 Jan 1999 16:50:06 -0800 From: Mike Smith Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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