Changed the packet structure's data field to a 65536-byte array to need less malloc'ing and free'ing, significantly reducing heap fragmentation.
This commit is contained in:
@@ -71,7 +71,7 @@ typedef int (*NETSETLINKSTATE)(void *);
|
|||||||
|
|
||||||
typedef struct netpkt {
|
typedef struct netpkt {
|
||||||
void *priv;
|
void *priv;
|
||||||
uint8_t *data;
|
uint8_t data[65536]; /* Maximum length + 1 to round up to the nearest power of 2. */
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
struct netpkt *prev, *next;
|
struct netpkt *prev, *next;
|
||||||
|
|||||||
@@ -230,7 +230,6 @@ network_queue_put(int tx, void *priv, uint8_t *data, int len)
|
|||||||
temp = (netpkt_t *) malloc(sizeof(netpkt_t));
|
temp = (netpkt_t *) malloc(sizeof(netpkt_t));
|
||||||
memset(temp, 0, sizeof(netpkt_t));
|
memset(temp, 0, sizeof(netpkt_t));
|
||||||
temp->priv = priv;
|
temp->priv = priv;
|
||||||
temp->data = (uint8_t *) malloc(len);
|
|
||||||
memcpy(temp->data, data, len);
|
memcpy(temp->data, data, len);
|
||||||
temp->len = len;
|
temp->len = len;
|
||||||
temp->prev = last_pkt[tx];
|
temp->prev = last_pkt[tx];
|
||||||
@@ -266,8 +265,6 @@ network_queue_advance(int tx)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
first_pkt[tx] = temp->next;
|
first_pkt[tx] = temp->next;
|
||||||
if (temp->data != NULL)
|
|
||||||
free(temp->data);
|
|
||||||
free(temp);
|
free(temp);
|
||||||
|
|
||||||
if (first_pkt[tx] == NULL)
|
if (first_pkt[tx] == NULL)
|
||||||
@@ -284,8 +281,6 @@ network_queue_clear(int tx)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (temp->data != NULL)
|
|
||||||
free(temp->data);
|
|
||||||
free(temp);
|
free(temp);
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
} while (temp != NULL);
|
} while (temp != NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user