Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Mar 2010 12:25:29 +0100
From:      Rui Paulo <rpaulo@freebsd.org>
To:        jiani1012 <jiani1012@126.com>
Cc:        freebsd-net <freebsd-net@freebsd.org>
Subject:   Re: space of ath_node
Message-ID:  <06B53E1D-48A7-4739-9B94-CA6AC8AE902B@freebsd.org>
In-Reply-To: <cba400.f3c8.127ac9383f3.Coremail.jiani1012@126.com>
References:  <cba400.f3c8.127ac9383f3.Coremail.jiani1012@126.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On 30 Mar 2010, at 01:58, jiani1012 wrote:

> Hi,all   =20
>        A problem puzzled me in ath code. The following code in =
function  ath_node_alloc( ) shows the space allocated to an,
>=20
>> struct ath_ratectrl {
>> size_t arc_space;    /* space required for per-node state */
>> };=20
>=20
>> const size_t space =3D sizeof(struct ath_node) + =
sc->sc_rc->arc_space;
>> struct ath_node *an;
>> an =3D malloc(space, M_80211_NODE, M_NOWAIT|M_ZERO);
>=20
> but in the two lines below ,what is (an)[1]?  Where is the =
initialization of (an)[1]? What does it contain? Can you show me? and =
how to get the content of sn?
>=20
>> struct sample_node *sn =3D ATH_NODE_SAMPLE(an);       /*in sample.c*/
>> #define ATH_NODE_SAMPLE(an) ((struct sample_node *)&(an)[1])      =
/*in sample.h*/
>=20
> Otherwise, the struct ath_ratectrl has been used in structures =
ath_softc, sample_softc and so on. Is there any relations between them?

Think about memory in the following way:

an[0] .................................. an[1] ...................
      struct ath_node                          struct sample_node=20

Indexing an[1] gives the address past the end of struct ath_node, which =
is the start address of struct sample_node.

--
Rui Paulo




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?06B53E1D-48A7-4739-9B94-CA6AC8AE902B>