📄 mem.inc
字号:
virtual SetPrev:mptr=mb_setprev
virtual SetNext:mptr=mb_setnext
virtual SetSize:mptr=mb_setsize
virtual RawBlockSize:mptr=mb_rawblocksize
virtual BreakBlock:mptr=mb_breakblock
virtual MarkUsed:mptr=memory_block_markused
virtual Combine:mptr=memory_block_combine
virtual MarkFree:mptr=memory_block_markfree
virtual LockBlock:mptr=memory_block_lock
virtual UnLockBlock:mptr=memory_block_unlock
virtual AllocFail:mptr=memory_block_allocfail
}
TBLPTR
next dd ? ; Segment of the next block in memory.
; (Only used as a word. High word set to blank in init.)
; FFFF if this block is unused.
; 0000 if this is the last block.
; Mark this offset to be returned as where the caller can start at
; using this block of memory.
@memory_block_used_start label byte
; The following are only for unused blocks
next2 dd ? ; The segment of the next block if this block is unused.
; (Only used as a word. High word set to blank in init.)
ifdef _DO_SETPREV_
prev dd ? ; Segment of the previous block.
; (Only used as a word. High word set to blank in init.)
endif
blksize dw ? ; Size of the block in paragraphs.
; This should be the size of the allocateable area,
; (corrected for the bookkeeping area)
memory_block ends
ifdef _MAKE_MEMVMT_
; Make the VMT for the memory blocks
MAKE_VMT
endif
;mbsize = size @TableAddr_MEMORY_BLOCK
; memory_usedblock
; When a block of memory on the heap is in use, it's VMT is changed
; so that the block becomes used. The usedblock routines handle returning,
; in a faster way, the results for various block methods. The block
; methods for invalid operations on used blocks are quickly trapped,
; and can even vector to internal_error display routines.
; While the normal memory_block routines do extensive checking with the
; IsFree method, changing used blocks to this type should speed many
; operations
global memory_usedblock_init:proc
global memory_usedblock_getnext:proc
global memory_usedblock_scan:proc
global memory_usedblock_isfree:proc
global memory_usedblock_invalid:proc
global memory_usedblock_setnext:proc
global memory_usedblock_markfree:proc
global memory_usedblock_show:proc
global memory_usedblock_combine:proc
global memory_usedblock_lock:proc
global memory_usedblock_unlock:proc
memory_usedblock struc memory_block method {
init:mptr = memory_usedblock_init
virtual getnext:mptr=memory_usedblock_getnext
virtual ScanFree:mptr=memory_usedblock_scan
virtual IsFree:mptr=memory_usedblock_isfree
virtual SetPrev:mptr=memory_usedblock_invalid
virtual SetSize:mptr=memory_usedblock_invalid
virtual SetNext:mptr=memory_usedblock_setnext
virtual BreakBlock:mptr=memory_usedblock_invalid
virtual MarkFree:mptr=memory_usedblock_markfree
virtual MarkUsed:mptr=memory_usedblock_invalid
virtual show:mptr = memory_usedblock_show
virtual Combine:mptr=memory_usedblock_combine
virtual LockBlock:mptr=memory_usedblock_lock
virtual UnLockBlock:mptr=memory_usedblock_unlock
}
memory_usedblock ends
ifdef _MAKE_MEMVMT_
; Make the VMT for the memory usedblocks
MAKE_VMT
endif
; memory_endblock
; This block is placed at the end of the memory heap. It should
; be only a paragraph in size, just large enough for the bookkeeping
; info of the segment. This allows all other blocks on the heap to
; be guarranteed that a block follows them, and therefore they can all
; use simple segment arithmetic to calculate their size. While the
; size of the memory block can be made a part of the information that
; is stored for the free blocks, used blocks do not have room for this
; information. Since the block does not have access to the last segment
; variable of the heap, the ending block on the heap would have no way
; to calculate it's size if it is used, since the next pointer would
; be zero. This block handles the whole matter, by appearing to be a
; permanently used block at the end of the heap. Since the next pointer
; is zero, all heapwalks will stop with this block.
global memory_endblock_init:proc
global memory_endblock_show:proc
global memory_endblock_getnext:proc
global memory_endblock_ignore:proc
memory_endblock struc memory_usedblock method {
init:mptr = memory_endblock_init
virtual getnext:mptr = memory_endblock_getnext
virtual show:mptr = memory_endblock_show
virtual RawBlockSize:mptr=memory_endblock_getnext
virtual LockBlock:mptr=memory_endblock_ignore
virtual UnLockBlock:mptr=memory_endblock_ignore
}
memory_endblock ends
ifdef _MAKE_MEMVMT_
; Make the VMT for the memory endblocks
MAKE_VMT
endif
; MEMORY_SYSTEM
;
; init - Handles setting up a block of memory for memory allocation
; management.
; Arguments: DS:SI - Address of memory system object
; AX - 0 - Allocate maximum block.
; other - Size of desired block
; High-bit of AX - If 1 - Allow smaller block
; If 0 - Fail if not enough memory
; Returns: Memory block initialized.
; DS:SI unchanged.
; AX is size of actual block. (Note that maximum allocateable
; size is a paragraph less than this value because of
; memory_block bookkeeping.)
;
;
; alloc - Allocates an area in the memory block.
; Arguments: DS:SI - Address of memory system object
; AX - Size in bytes of area to allocate
; Returns: AX is segment of memory block
; BX is the offset into the memory block
; DS:SI unchanged
; If no block can be allocated, then AX is zero, and
; BX is the size of the largest block.
;
;
; free - Frees an allocated area
; Arguments: DS:SI - Address of the memory system object
; AX - Segment of area to be freed
; Returns: None
;
;
; blockofs - Returns fixed offset within memory blocks that marks the
; start of information that is only optionally used if the
; block is empty. This allows descendants to increase the
; amount of bookkeeping information used in the memory_block
; for all blocks, free and used.
; Users of the memory system only need to store segment
; values of alloced blocks, and they can use this function to
; fill in the offset if they want.
; Arguments: AX Segment of block to find this value for
; (If AX=0, then root block's blockofs is returned.)
; Returns: AX with fixed offset value
;
;
; resetrover - Makes rover point at the root block. This causes the
; next alloc call to use the earliest possible free
; block in the heap.
;
;
;
; show - Displays global status information for the memory_system, and
; then calls the show method for each of the individual memory
; blocks.
;
;
; freeall - Frees all blocks on the heap.
;
;***** Lower Level Calls:
;
; FindPrev - Finds the address if the block current to the previous block.
; Arguments: DS:SI - Address of memory system
; AX - Segment address of block to find previous for
; Returns: AX - Segment of previous memory block
; AX=0 if a previous block was not found.
; DS:SI - Unchanged
; This is the global memory system manager object.
global memory_system_init:proc
global memory_system_deinit:proc
global memory_system_show:proc
global memory_system_alloc:proc
global memory_system_free:proc
global memory_system_blockofs:proc
global memory_system_freeall:proc
global memory_system_resetrover:proc
global memory_system_findprev:proc
memory_system STRUC METHOD {
init:mptr = memory_system_init
virtual deinit:mptr=memory_system_deinit
virtual show:mptr=memory_system_show
virtual alloc:mptr=memory_system_alloc
virtual free:mptr=memory_system_free
blockofs:mptr=memory_system_blockofs
virtual freeall:mptr=memory_system_freeall
virtual resetrover:mptr=memory_system_resetrover
virtual FindPrev:mptr=memory_system_findprev
}
TBLPTR
blocksize dw ? ; Size of the block of memory managed by this
; memory system manager.
root dw ? ; The first block of memory
last dw ? ; The last block of memory
rover dw ? ; Moves through memory
freespace dw ? ; Remembers the amount of free space total in paragraphs
usedspace dw ? ; Remembers the amount of used memory in paragraphs
memory_system ends
;mssize = size @TableAddr_MEMORY_system
ifdef _MAKE_MEMVMT_
; Make the VMT for the memory endblocks
MAKE_VMT
endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -