INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a Computer / IT professional? Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
Favorite Forums
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)
Feedback
"...Your site has saved me hours of work that I cannot begin to express my satisfaction..."
Geography
Where in the world do Tek-Tips members come from?
|
|
The Ultimate Method for Writing Memory to a File
Posted: 15 Jul 00
|
With all of the questions about accessing memory with QB I decided to show everyone the ultimate method for saving large blocks of RAM to a file.
A conventional loop setting memory segments and then PEEKing at each byte in each 16 byte segment could require many many minutes to read and write the RAM that this program accesses in a fraction of a second. It appears to be several times faster (and more flexible) than the BSAVE command.
How fast? When this program is timed, using Interrupt 21 function 2c, running on a K62/350, it comes in at .05 seconds. It's hard to get a more accurate time with DOS since the system timer resolution is .05 seconds. In any case, this little routine gets and saves one megabyte of memory in very short order.
You will need QB45 or better and must load the QB library (or equivalent) with the command line "QB /L QB.QLB".
' $DYNAMIC DEFINT A-Z 'Declare the registers. Don't use ' $INCLUDE: QB.BI to load 'them. This one requires that DS is a long integer. 'Don't try to modify the other registers or use this 'declaration in a different program.
TYPE RegTypeX AX AS INTEGER BX AS INTEGER CX AS INTEGER DX AS INTEGER BP AS INTEGER SI AS INTEGER DI AS INTEGER FLAGS AS INTEGER DS AS LONG ES AS INTEGER END TYPE DIM InRegs AS RegTypeX, OutRegs AS RegTypeX
'MemFile$ will contain the name of the file we want to write. MemFile$ = "1STMEG" + CHR$(0) InRegs.AX = &H3C00 InRegs.CX = &H20 InRegs.DS = VARSEG(MemFile$) InRegs.DX = SADD(MemFile$) CALL InterruptX(&H21, InRegs, OutRegs)'Create an empty file InRegs.AX = &H3D01 '01 = open the file for write access InRegs.DS = VARSEG(MemFile$) InRegs.DX = SADD(MemFile$) CALL InterruptX(&H21, InRegs, OutRegs) 'Open the file hFile = OutRegs.AX 'hFile is the handle for the file
FOR Segment& = 0 TO 65535 STEP 2048 'Skip segs already read InRegs.AX = &H4000 InRegs.BX = hFile InRegs.CX = 32767 'Read this many bytes InRegs.DS = Segment& 'Begin with this segment InRegs.DX = 0 'Start at offset 0 'Write the bytes to the file CALL InterruptX(&H21, InRegs, OutRegs NEXT InRegs.AX = &H3E00 InRegs.BX = hFile CALL InterruptX(&H21, InRegs, OutRegs) 'Close the file
|
Back to QBasic FAQ Index
Back to QBasic Forum |
|
 |
|
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close