Discussion:
space of ath_node
(too old to reply)
jiani1012
2010-03-30 00:58:21 UTC
Permalink
Hi,all
A problem puzzled me in ath code. The following code in function ath_node_alloc( ) shows the space allocated to an,
struct ath_ratectrl {
size_t arc_space; /* space required for per-node state */
};
const size_t space = sizeof(struct ath_node) + sc->sc_rc->arc_space;
struct ath_node *an;
an = malloc(space, M_80211_NODE, M_NOWAIT|M_ZERO);
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?
struct sample_node *sn = ATH_NODE_SAMPLE(an); /*in sample.c*/
#define ATH_NODE_SAMPLE(an) ((struct sample_node *)&(an)[1]) /*in sample.h*/
Otherwise, the struct ath_ratectrl has been used in structures ath_softc, sample_softc and so on. Is there any relations between them?

Thank you!
Jeny
Rui Paulo
2010-03-30 11:25:29 UTC
Permalink
Post by jiani1012
Hi,all
A problem puzzled me in ath code. The following code in function ath_node_alloc( ) shows the space allocated to an,
struct ath_ratectrl {
size_t arc_space; /* space required for per-node state */
};
const size_t space = sizeof(struct ath_node) + sc->sc_rc->arc_space;
struct ath_node *an;
an = malloc(space, M_80211_NODE, M_NOWAIT|M_ZERO);
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?
struct sample_node *sn = ATH_NODE_SAMPLE(an); /*in sample.c*/
#define ATH_NODE_SAMPLE(an) ((struct sample_node *)&(an)[1]) /*in sample.h*/
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

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

--
Rui Paulo

Loading...