Associates the external memory pointed to by the data
pointer with the netbuf buf. The size of the external
memory is given by size. Any memory previously
allocated to the netbuf is deallocated. The difference between allocating
memory for the netbuf with netbuf_alloc()
and allocating memory using, e.g., malloc() and
referencing it with netbuf_ref() is that in the former
case, space for protocol headers is allocated as well which makes processing
and sending the buffer faster.
Example 4-1. This example shows a simple use of the netbuf_ref()
int
main()
{
struct netbuf *buf;
char string[] = "A string";
/* create a new netbuf */
buf = netbuf_new();
/* reference the string */
netbuf_ref(buf, string, sizeof(string));
/* do something with the netbuf */
/* [...] */
/* deallocate netbuf */
netbuf_delete(buf);
}
|