Optimize malloc for block reuse
This commit is contained in:
parent
8d541ce498
commit
34eb0a2bd6
9
heap.asm
9
heap.asm
@ -15,7 +15,7 @@ verbose_malloc:
|
|||||||
;
|
;
|
||||||
; Header:
|
; Header:
|
||||||
; word ptr to next item (this implies its size)
|
; word ptr to next item (this implies its size)
|
||||||
; byte 00 = free, FF = in use
|
; byte 00 = free, >0 used (refcount)
|
||||||
malloc:
|
malloc:
|
||||||
push ax
|
push ax
|
||||||
mov si,heap
|
mov si,heap
|
||||||
@ -31,12 +31,10 @@ malloc:
|
|||||||
sub ax,cx
|
sub ax,cx
|
||||||
je .reuse ; entry has exact length
|
je .reuse ; entry has exact length
|
||||||
jc .next ; entry too short
|
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
|
.reuse: ; exact length
|
||||||
mov byte [si+2],0xFF
|
mov byte [si+2],0xFF
|
||||||
add si, 0x03
|
jmp .end
|
||||||
pop ax
|
|
||||||
ret
|
|
||||||
.append: ; append to last item
|
.append: ; append to last item
|
||||||
mov ax, si
|
mov ax, si
|
||||||
add ax, 3
|
add ax, 3
|
||||||
@ -47,6 +45,7 @@ malloc:
|
|||||||
mov word si,[si]
|
mov word si,[si]
|
||||||
mov byte [si],0x0000
|
mov byte [si],0x0000
|
||||||
pop si
|
pop si
|
||||||
|
.end:
|
||||||
add si, 0x03
|
add si, 0x03
|
||||||
pop ax
|
pop ax
|
||||||
ret
|
ret
|
||||||
|
Loading…
Reference in New Issue
Block a user