nameless_centurian
Gawd
- Joined
- Apr 4, 2003
- Messages
- 836
so i was digging through some books at home trying to answer some questions. i even found some books that belong to my dad.
i was curious how dynamic memory allocation worked.
well, as it turns out, allocation is fairly easy. you just do something like
now, this is all from memory, and you'll have to forgive my pseudo-assembly... so feel free to correct any errors.
...now i have 2 questions
1) it appears as though the program is treating the memory at the end of the program as kind of a reverse stack.... yet the book called it a heap. what gives?
2) none of the books demonstrated a deletion of dynamic memory and a return to the heap of the allocated memory. how is this accompished?
edit: made some changes in errors that i caught
i was curious how dynamic memory allocation worked.
well, as it turns out, allocation is fairly easy. you just do something like
Code:
jump next immediate mode
heaptr: .block of memory the size of a word that keeps track of first available memory spot
somptr: a block the size of a word, used as a pointer to dynamic memory
next: lda with initheap in immediate mode
sta to heaptr in direct mode
main: call new
sta somptr in direct mode
STOP
new: lda heaptr in direct mode
adda with wordsize in immediate mode
sta heaptr
suba wordsize in immediate mode
return from new
initheap: .block the size of a word
now, this is all from memory, and you'll have to forgive my pseudo-assembly... so feel free to correct any errors.
...now i have 2 questions
1) it appears as though the program is treating the memory at the end of the program as kind of a reverse stack.... yet the book called it a heap. what gives?
2) none of the books demonstrated a deletion of dynamic memory and a return to the heap of the allocated memory. how is this accompished?
edit: made some changes in errors that i caught