To get rid of the awful (and buggy!) ALIGNPTR stuff that used to
be in coap_pdu_clear(), a new memory type COAP_PDU_BUF has been
introduced for Contiki. This allows storing the message payload
in its own memory chunk similar to the way it is stored for lwIP.
the old implementation stuffed the pdu struct in front of the
transport-level pbuf, and preserved it on the stack while the packages
were sent.
this had two advantages:
* saving ram
* preserving the other implementation's structure of pdu->hdr == pdu+1
(ie. starting right after the pdu struct)
but two disadvantages:
* bad readability and pointer juggling in the send routine
* relying on the send function to block until the package is out (which
works for simple implementations of lwip drivers but not dma etc)
if something really assumes the contiguous memory structure, it will
show (unfortunately by corrupting other pdu structs), and chances are
people use ->hdr anyway.
those things need to reside in mem.h (instead of living implementation
dependently inside mem.c) because coap_malloc_type(MY_TYPE, ...) is
converted to memp_malloc(MEMP_MY_TYPE) and thus needs to be done in the
preprocessor. (the alternative would be to switch on the MY_TYPE enum,
which would be harder to maintain).
Two new functions coap_malloc_type() and coap_free_type() have been
added to centralize the typed memory allocation for Contiki and LWIP.
Currently, calls to memb_alloc(), memp_malloc() and coap_malloc() are
distributed across several modules. The idea of the new functions is
to centralize memory management in one place (mem.c). coap_malloc()
and coap_free() are still available as wrappers for the new functions.