chg: Use static memory buffer for MAC address conversion - #39
Conversation
|
I currently see no use case for more than one buffer. |
|
Use case is avoiding dynamic memory allocation. Also this simplifies use in code a bit as the return value can be used directly by the caller. |
|
|
||
| char* hwaddr2c(uint8_t* hwaddr) { | ||
| char* str = calloc(18, sizeof(char)); | ||
| #define hwaddr_strcount 16u |
There was a problem hiding this comment.
Please comment in code on the intention of this constant.
Since we currently only need one of these buffers set it to one.
573b57e to
29b2961
Compare
This patch uses several buffers in a round-robin fashion to avoid overwriting a just-returned result. The number of buffers internally used is choosen at 16 to allow for enough spare buffers even when more complicated situations need to be processed.
29b2961 to
108d87e
Compare
|
using multiple buffers is required when logging more than one address on the same line. I am using a similar mechanism for debug output in l3roamd, allowing either 4 small buffers or one large one. It should be easy enough to increase when demand arises. OTOH: Does the memory overhad of those 18 Bytes really justify not merging the patch set as it is? |
This avoids memory allocations when trying to output the hardware MAC address in various situations.
Multiple buffers are provided to allow for multiple MAC addresses to be processed before copies need to be created.