Date: Wed, 02 Aug 2000 12:34:09 -0700 From: Mike Smith <msmith@freebsd.org> Cc: "Daniel C. Sobral" <dcs@newsguy.com>, chris@calldei.com, freebsd-hackers@FreeBSD.ORG Subject: Re: malloc to arrays? Message-ID: <200008021934.MAA01407@mass.osd.bsdi.com> In-Reply-To: Your message of "Wed, 02 Aug 2000 23:13:05 %2B0400." <200008021913.XAA00739@cicuta.babolo.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
> Yes, and whan I use u_int32_t *(tcpcash_addr[256]) declaration, > I can use tcpcash_addr[x][y], and I must use > tcpcash_addr[x * 256 + y] if declaration is u_int32_t *tcphash_haddr, > I cant use if u_int32_t **tcphash_haddr, > because of need of array of pointers in addition to array of arrays, > and the only clean but not nice way I know is > struct tcphash_haddr {u_int32_t tcpcash_addr[256];}; > struct tcphash_haddr *tcphash_haddr; > but tcphash_haddr[x].tcpcash_addr[y] is not so clear > as tcpcash_addr[x][y]... > = > Is the reason to use *(foo[nmemb]) syntax clear enough? It's only "clear" insofar as it's "clear" that the code is terrible. #define TCPCASH_ROWSIZE 256 #define TCPCASH_COLSIZE 256 #define TCPCASH_ADDR(x) ((x) * TCPCASH_ROWSIZE) u_int32_t *tcpcash_addr tcpcash_addr =3D (typeof(tcpcash_addr)) malloc(sizeof(*tcpcash_addr) * = TCPCASH_ROWSIZE * = TCPCASH_COOLSIZE); =2E.. foo =3D tcpcash[TCPCASH_ADDR(x)]; This is fast and unambiguous, as well as keeping all the magic numbers = away from the actual code. Oh, and you spell "cache" like that. "cash" is money. -- = =2E.. every activity meets with opposition, everyone who acts has his rivals and unfortunately opponents also. But not because people want to be opponents, rather because the tasks and relationships force people to take different points of view. [Dr. Fritz Todt] To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200008021934.MAA01407>