From owner-freebsd-hackers Wed Aug 12 15:49:02 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA27171 for freebsd-hackers-outgoing; Wed, 12 Aug 1998 15:49:02 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from whistle.com (s205m131.whistle.com [207.76.205.131]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA27166 for ; Wed, 12 Aug 1998 15:49:01 -0700 (PDT) (envelope-from archie@whistle.com) Received: (from smap@localhost) by whistle.com (8.7.5/8.6.12) id PAA02938; Wed, 12 Aug 1998 15:48:36 -0700 (PDT) Received: from bubba.whistle.com(207.76.205.7) by whistle.com via smap (V1.3) id sma002934; Wed Aug 12 15:48:24 1998 Received: (from archie@localhost) by bubba.whistle.com (8.8.7/8.6.12) id PAA09142; Wed, 12 Aug 1998 15:48:23 -0700 (PDT) From: Archie Cobbs Message-Id: <199808122248.PAA09142@bubba.whistle.com> Subject: Re: Allocating memory in a network device driver In-Reply-To: <199808122122.XAA03579@chouette.inria.fr> from Emmanuel Duros at "Aug 12, 98 11:22:54 pm" To: Emmanuel.Duros@sophia.inria.fr (Emmanuel Duros) Date: Wed, 12 Aug 1998 15:48:23 -0700 (PDT) Cc: freebsd-hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL38 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Emmanuel Duros writes: > I am currently writing a network device driver and I need clarification > on how to allocate memory. > > I have seen in many device drivers allocating memory in the following > way: > > u_char *buf; > buf = malloc( BUFSIZ, M_DEVBUF, M_NOWAIT); > > Do we get the same result with : ? > > u_char buf[BUFSIZ]; The kernel malloc works just like the libc malloc .. man malloc(3). The extra arguments are the type (you must specify the same type when you free() the memory) and whether or not it's OK to put the current process to sleep in order to get the memory. If you say M_WAITOK, then malloc() never fails but may put the process to sleep. If you say M_NOWAIT, then it may fail but will not put the process to sleep. In general, M_NOWAIT is required for any code running during an interrupt (ie, the current process should not be put to sleep), otherwise M_WAITOK is ok. -Archie ___________________________________________________________________________ Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message