From: Brian Haley <haley@zk3.dec.com>
Subject: Re: Kernel memory
Date: Fri, 03 Aug 2001 09:43:54 -0400 [thread overview]
Message-ID: <3B6AAA99.4E07EB07@zk3.dec.com> (raw)
In-Reply-To: 2f6bec0a.0108022055.24136296@posting.google.com
"Ginny E. Kim" wrote:
> > X int statesize = 5737;
> > X static state_t **table = NULL;
> > X
> > X int table_init()
> > X {
> > X MALLOC(table, state_t **, sizeof(state_t *) * statesize,
> > X M_TEMP, M_NOWAIT);
> > X ......................
> > X }
> >
> > MALLOC is used when the size of the storage can be specified as either
> > a hard coded constant, a #define contant, or a sizeof(...) constant.
> >
> > MALLOC_VAR is used when the size of the storage is passed as a
> > variable. 'statesize' is a variable and thus you should be using
> > MALLOC_VAR
> >
> > Bob Harris
>
> I used the size of the storage of MALLOC be specified as a hard coded constant.
> For instance,
> #define STATESIZE 5737
> statesize = STATESIZE
> I don't think 'statesize' is a variable.
> MALLOC() in Tru64 V4.0F doesn't have this problem.
> Doesn't the type or flag of malloc() have the problem?
Bob is absolutely right here, your code has a bug. 'statesize' is a global
variable, this means its value can be modified, for example with dbx.
For this reason, 'sizeof(state_t *) * statesize' cannot be calculated at
compile time, which is what's required if you're using MALLOC.
You have had a lot of questions here lately, most of which can be
answered by reading the documentation. Please re-read some of it
again, you will probably notice a lot of things you didn't see the
first time now that you've had a chance to write some code.
-Brian
---------------------------------------------------
Brian P. Haley Brian.Haley@compaq.com
Tru64 UNIX Networking Group
next prev parent reply other threads:[~2001-08-03 13:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-02 8:02 Kernel memory Ginny E. Kim
2001-08-02 13:01 ` Bob Harris
2001-08-03 4:55 ` Ginny E. Kim
2001-08-03 13:43 ` Brian Haley [this message]
2001-08-04 6:32 ` Ginny E. Kim
2001-08-10 15:48 ` Brian Haley
2001-08-13 5:21 ` Ginny E. Kim
2001-08-13 18:47 ` Brian Haley
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox