Ethereal-dev: Re: [Ethereal-dev] ntohl(), pntohl(), g_ntohl() ?

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxx>
Date: Thu, 15 Aug 2002 09:51:01 -0700
On Thu, Aug 15, 2002 at 09:27:19AM +0200, Yaniv Kaul wrote:
> Thanks. Follow up question, on performance:
> Which method is preferable:
> (1)
> 
> struct some_hdr hdr;
> tvb_memcpy(tvb, (guint8 *)&hdr, offset, sizeof(hdr));
> proto_tree_add_X(...,hdr.a);
> proto_tree_add_Y(...,hdr.b);
> 
> -or-
> 
> (2)
> 
> struct some_hdr hdr;
> hdr.a = tvb_get_X();
> hdr.b = tvb_get_Y();
> proto_tree_add_X(...,hdr.a);
> proto_tree_add_Y(...,hdr.b);

I prefer neither of those.

I prefer

	(3)

	a = tvb_get_X();
	proto_tree_add_X(...,a);
	b = tvb_get_Y();
	proto_tree_add_Y(...,b);

or

	(4)

	proto_tree_add_item(...);
	proto_tree_add_item(...);

which address the issue I mentioned earlier, of "short" packets - i.e.,
don't require that field "b" exist in order to put field "a" into the
tree.