Optimize malloc for block reuse

This commit is contained in:
Nero 2019-03-16 11:08:11 +00:00
parent 8d541ce498
commit 34eb0a2bd6
1 changed files with 4 additions and 5 deletions

View File

@ -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