From 41dc12ebf3292cb67f5a455fd2d06db6b42c76b7 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 2 Dec 2023 19:53:50 +0200 Subject: [PATCH] Reuse existing shmpiece structures, do not allocate duplicates. --- memory.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/memory.cpp b/memory.cpp index 9833d822..495f271c 100644 --- a/memory.cpp +++ b/memory.cpp @@ -2190,7 +2190,6 @@ bool mapped_malloc (addrbank *ab) { int id; void *answer; - shmpiece *x; bool rtgmem = (ab->flags & ABFLAG_RTG) != 0; static int recurse; @@ -2262,16 +2261,29 @@ bool mapped_malloc (addrbank *ab) answer = ab->baseaddr; } if (answer != (void *) -1) { - x = xmalloc (shmpiece, 1); + shmpiece *xx = shm_start; + shmpiece *x = NULL; + // if we already have shmpiece for this address space: reuse it + while (xx) { + if (answer == xx->native_address) { + x = xx; + break; + } + xx = xx->next; + } + if (!x) { + // no old shmpice: allocate new + x = xcalloc(shmpiece, 1); + x->next = shm_start; + x->prev = NULL; + if (x->next) + x->next->prev = x; + shm_start = x; + } x->native_address = (uae_u8*)answer; x->id = id; x->size = ab->reserved_size; x->name = ab->label; - x->next = shm_start; - x->prev = NULL; - if (x->next) - x->next->prev = x; - shm_start = x; ab->baseaddr = x->native_address; if (ab->baseaddr) { if (md.hasbarrier) { @@ -3203,7 +3215,6 @@ void memory_init (void) chipmem_bank.reserved_size = 0; bogomem_bank.reserved_size = 0; - kickmem_bank.baseaddr = NULL; extendedkickmem_bank.baseaddr = NULL; extendedkickmem_bank.reserved_size = 0; extendedkickmem2a_bank.baseaddr = NULL; @@ -3220,6 +3231,7 @@ void memory_init (void) custmem1_bank.baseaddr = NULL; custmem2_bank.baseaddr = NULL; + mapped_free(&kickmem_bank); kickmem_init(); _tcscpy (currprefs.romfile, _T("")); currprefs.romextfile[0] = 0; -- 2.47.3