[lwip-devel] Best method to allocate space for external packets
From:
Thomas Taranowski
Subject:
[lwip-devel] Best method to allocate space for external packets
Date:
Thu, 16 Aug 2007 11:04:23 -0700
I have a scenario where I want to allocate a pbuf for an incoming packet, but I want that pbuf payload to reside in a region of shared memory that is specified at runtime, and is external to the network stack. This newly allocated pbuf is then passed to the driver, which then DMAs an incoming payload directly into the space.
So, to break it down, I want to make the pbuf framework allocate space from an external pool for me, and I'd like to make the mechanism generic enough so that it will be of general use.
I'm trying to sort out which of the following methods would make the best sense...
Use the PBUF_ROM flag. When doing the pbuf_alloc with a PBUF_ROM flag set, have the PBUF_ROM case allocate from an external pool. However, the method to use for the actual allocation is unclear in my mind. I'm thinking perhaps a new MEMP type that refers to an external pool(not part of the memp static buffer), or maybe a mem_malloc that can allocate from an external pool. The alternative would be to implement a custom allocator for the pool, but it seems like I should be able to take advantage of the allocation mechanisms already built-in.
Allocate externally. I could allocate the necessary space external to the stack, then use pbuf_ref to refer to the payload. However, I'd prefer using a pbuf_alloc approach, primarily because the code is already there.
Memcpy. I could also allocate the space externally, then memcpy the data to a PBUF_POOL. I don't really care for this method because it adds an additional layer of memcpy that I don't need, but it has the advantage of being easy.