From 5b87c654e1b157b917399e88df4fbf2817672170 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 2 May 2020 02:09:10 +0200 Subject: [PATCH] Changed the packet structure's data field to a 65536-byte array to need less malloc'ing and free'ing, significantly reducing heap fragmentation. --- src/include/86box/network.h | 2 +- src/network/network.c | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/include/86box/network.h b/src/include/86box/network.h index 85b2d8276..f4e653a33 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -71,7 +71,7 @@ typedef int (*NETSETLINKSTATE)(void *); typedef struct netpkt { void *priv; - uint8_t *data; + uint8_t data[65536]; /* Maximum length + 1 to round up to the nearest power of 2. */ int len; struct netpkt *prev, *next; diff --git a/src/network/network.c b/src/network/network.c index de9c2ed1c..5f4c6dbaf 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -230,7 +230,6 @@ network_queue_put(int tx, void *priv, uint8_t *data, int len) temp = (netpkt_t *) malloc(sizeof(netpkt_t)); memset(temp, 0, sizeof(netpkt_t)); temp->priv = priv; - temp->data = (uint8_t *) malloc(len); memcpy(temp->data, data, len); temp->len = len; temp->prev = last_pkt[tx]; @@ -266,8 +265,6 @@ network_queue_advance(int tx) return; first_pkt[tx] = temp->next; - if (temp->data != NULL) - free(temp->data); free(temp); if (first_pkt[tx] == NULL) @@ -284,8 +281,6 @@ network_queue_clear(int tx) return; do { - if (temp->data != NULL) - free(temp->data); free(temp); temp = temp->next; } while (temp != NULL);