![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

An example of file access and memory allocation:
\ Use S" filename.ext" FILE>MEM
: FILE>MEM ( filename count -- memAddr filesize )
R/O OPEN-FILE THROW >R
R@ FILE-SIZE THROW D>S ( size )
DUP ALLOCATE THROW ( Allocate a Memory Block )
DUP ROT R@ READ-FILE THROW ( bytes-read )
R> CLOSE-FILE THROW ;
: TEST ( -- ) \ Display file contents
S" myfile.txt" FILE>MEM ( MemAddress FileSize )
CR 2DUP TYPES ( Display File Contents )
DROP ( discard size )
FREE THROW ( Release Memory - we must do this! ) ;
Note that TYPES is a version of TYPE that handles line feeds etc.
Mike
-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com]On Behalf
Of Schmitt Louis Jean-Pierre
Sent: Monday, December 03, 2001 9:44 AM
To: sftalk_at_forth.com
Subject: [sftalk] File to memory and memory to file allot + mem to
swiftforth
y tank you Mike for help
my next problems
a) Wat is the command to permit extend memory area
b) to load an file to available memory
c) to store an memory area to an file
Tanks
Louis Jean-Pierre
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Mon Dec 03 2001 - 10:50:56 PST
This archive was generated by hypermail 2.2.0 : Sat Nov 22 2008 - 03:04:20 PST