programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: File to memory and memory to file allot + mem to swiftforth

From: Rick VanNorman <rick_at_forth.com>
Date: Sat, 12 Jan 2002 11:12:10 -0800

Damir,

If I assume that the question is in reference to the opening
and general access of the file in memory, you do nothing
different. The word TYPES is intended to act on reasonable
ascii strings, which might include embedded cr, lf, or bs
characters, so using TYPES on a true binary file would probably
produce unwanted results.

Rick

*********** REPLY SEPARATOR ***********

On 1/12/2002 at 8:04 PM Damir wrote:

>On Mon, 3 Dec 2001 10:51:02 -0800, you wrote:
>
>>
>>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 )=20
>> DUP ROT R@ READ-FILE THROW ( bytes-read )
>> R> CLOSE-FILE THROW ;
>>
>>: TEST ( -- ) \ Display file contents
>> S" myfile.txt" FILE>MEM ( MemAddress FileSize )=20
>> CR 2DUP TYPES ( Display File Contents )=20
>> DROP ( discard size )=20
>> FREE THROW ( Release Memory - we must do this! ) ;
>>
>>
>>Note that TYPES is a version of TYPE that handles line feeds etc.
>>
>>Mike
>
>What to do if extension is bin, S" myfile.bin"?

----------------------------------------------------------------------
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 Sat Jan 12 2002 - 11:13:37 PST

This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:21 PST