08-14-2003, 07:38 AM
Some of you may remember the memory routines I posted here a while ago. I have since improved them to make them a little more general purpose. The routines use DIrectQB's EMS peek and poke commands, but it could be made to work with any XMS/EMS library. The memory managment routines provide a block list of memory which can be malloced and freed (in a similar fashion to C's functions) to get a pointer (which is just an integer) to a block of memory. Two functions, memStore and memLoad allow you to store and retreive values and structures from EMS.
The pointer aspect allows more advanced structures such as linked lists to be made in QB, for example:
Working with the routines has a slight amount of overhead, for example to modify something store in EMS, you need to fetch it with memLoad, change it and then restore it using memStore.
The major benefits of using the library is that EMS can be used instead of conventional memory for storing large arrays and structs and data structures such as linked lists and binary trees can be created using pseudo pointers.
I have the routines working and could write a number of demos showing how various things can be acheived with them. How many people are actually interested in seeing/using the code, there didn't seem to be a large amount of interest when I posted the code for the original routines a while ago.
The pointer aspect allows more advanced structures such as linked lists to be made in QB, for example:
Code:
const SIZEOFNODE = 4
const NULL = -1
type nodeType
values as integer
link as integer
end type
dim rootNode as nodeType
dim linkNode as nodeType
dim rootPtr as integer
rootPtr = malloc%(SIZEOFNODE)
rootNode.value = 10
rootNode.link = malloc(SIZEOFNODE)
memStore varseg(rootNode), varptr(rootNode), rootPtr, SIZEOFNODE
linkNode.value = 20
linkNode.link = NULL
memStore varseg(linkNode), varptr(linkNode), rootNode.link, SIZEOFNODE
Working with the routines has a slight amount of overhead, for example to modify something store in EMS, you need to fetch it with memLoad, change it and then restore it using memStore.
The major benefits of using the library is that EMS can be used instead of conventional memory for storing large arrays and structs and data structures such as linked lists and binary trees can be created using pseudo pointers.
I have the routines working and could write a number of demos showing how various things can be acheived with them. How many people are actually interested in seeing/using the code, there didn't seem to be a large amount of interest when I posted the code for the original routines a while ago.