about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <serpilliere@users.noreply.github.com>2021-06-18 14:40:50 +0200
committerGitHub <noreply@github.com>2021-06-18 14:40:50 +0200
commit069440e8b4517a0ff93b94b4f89598e1695a429a (patch)
tree1ece2ea226d53abde372a35a4f4e554e0a6b29a3
parent42528eff158475d1eca930b06754003242d5f1c1 (diff)
parent5ec43c63a473c49a3ed52487ee4399471a47df0a (diff)
downloadmiasm-069440e8b4517a0ff93b94b4f89598e1695a429a.tar.gz
miasm-069440e8b4517a0ff93b94b4f89598e1695a429a.zip
Merge pull request #1374 from serpilliere/opt_mem_access
Optimise heap manipulation for mem accesses
-rw-r--r--miasm/jitter/vm_mngr.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/miasm/jitter/vm_mngr.c b/miasm/jitter/vm_mngr.c
index 5e20670a..9fe8ab65 100644
--- a/miasm/jitter/vm_mngr.c
+++ b/miasm/jitter/vm_mngr.c
@@ -36,21 +36,25 @@
 #define MAX(a,b)  (((a)>(b))?(a):(b))
 
 // #define DEBUG_MIASM_AUTOMOD_CODE
+#define MEMORY_ACCESS_LIST_INITIAL_COUNT 100
 
+/*
+  To avoid alloc/free for each instruction access, the buffer is allocated here,
+  and is increased depending of program needs.
+ */
 void memory_access_list_init(struct memory_access_list * access)
 {
-	access->array = NULL;
-	access->allocated = 0;
+	access->array = malloc(MEMORY_ACCESS_LIST_INITIAL_COUNT * sizeof(struct memory_access));
+	if (access->array == NULL) {
+		fprintf(stderr, "cannot realloc struct memory_access access->array\n");
+		exit(EXIT_FAILURE);
+	}
+	access->allocated = MEMORY_ACCESS_LIST_INITIAL_COUNT;
 	access->num = 0;
 }
 
 void memory_access_list_reset(struct memory_access_list * access)
 {
-	if (access->array) {
-		free(access->array);
-		access->array = NULL;
-	}
-	access->allocated = 0;
 	access->num = 0;
 }