about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2021-06-10 14:32:43 +0200
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2021-06-10 14:32:43 +0200
commit5ec43c63a473c49a3ed52487ee4399471a47df0a (patch)
tree1f7ce542929c490deda2634d3a33b1e463fb057e
parentdd4bc5f7acfbfa510afc56d2e1d1f2e15e9bedfa (diff)
downloadmiasm-5ec43c63a473c49a3ed52487ee4399471a47df0a.tar.gz
miasm-5ec43c63a473c49a3ed52487ee4399471a47df0a.zip
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;
 }