From 34eb0a2bd66dfa3a99252d2618c9c8ed5b1c4c12 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Sat, 16 Mar 2019 11:08:11 +0000 Subject: [PATCH] Optimize malloc for block reuse --- heap.asm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/heap.asm b/heap.asm index 9035b6a..f92e978 100644 --- a/heap.asm +++ b/heap.asm @@ -15,7 +15,7 @@ verbose_malloc: ; ; Header: ; word ptr to next item (this implies its size) -; byte 00 = free, FF = in use +; byte 00 = free, >0 used (refcount) malloc: push ax mov si,heap @@ -31,12 +31,10 @@ malloc: sub ax,cx je .reuse ; entry has exact length jc .next ; entry too short - jmp .next ; we'd have to split + jmp .next ; we'd have to split, not implemented yet .reuse: ; exact length mov byte [si+2],0xFF - add si, 0x03 - pop ax - ret + jmp .end .append: ; append to last item mov ax, si add ax, 3 @@ -47,6 +45,7 @@ malloc: mov word si,[si] mov byte [si],0x0000 pop si +.end: add si, 0x03 pop ax ret