May 05, 2024, 11:28:00 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


File I/O

Started by Bruce Peaslee, December 28, 2005, 11:10:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

I'm getting to the point where some I/O would be useful. Maybe a short example?ÂÃ,  ÂÃ, ::)

Also, FileRequest() returns type HEAP. How does that work?

Thanks.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

See editor.src.  Uses file I/O.  Or ask a specific question ;)

HEAP is the same as string.  It is just dynamically allocated, the compiler handles it internally.
Ionic Wind Support Team

Bruce Peaslee

Quote from: Ionic Wizard on December 28, 2005, 11:12:27 AM
See editor.src.ÂÃ,  Uses file I/O.ÂÃ,  Or ask a specific question ;)

Duh.ÂÃ,  :-[ÂÃ,  I was just studying it, too.

Quote from: Ionic Wizard on December 28, 2005, 11:12:27 AM
HEAP is the same as string.ÂÃ,  It is just dynamically allocated, the compiler handles it internally.

Got it.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

I assume that HEAP is the same as in IB, where it works like this:
pointer pMem;
pMem = AllocHeap(6);
*(string)pMem = "Hello"; // five characters plus the null
return *(string)pMem;


And then anything that uses that function, the compiler will call FreeHeap after the statement is done executing. I do wonder though, how it's different to return the type STRING rather than HEAP, what the compiler does differently.

Ionic Wind Support Team

Use heap when the length of the returned string is an unknown at compile time.   Returning a string does the same memory management but the length of the string itself is fixed.

FileRequest can return an unlimited amount of multiple selected filenames.  A string or dstring type wouldn't work since we don't know how many files a user is going to select, and you wouldn't want a limit on that.

Ionic Wind Support Team

Bruce Peaslee

Here's a question. How do I read/write by UDT to disk?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

write(file, udt, len(udt));
read(file, udt, len(udt));

use SEEK for positioning.

//read the 4th record
seek(file, len(udt) * 3);
reac(file, udt, len(udt);

Ionic Wind Support Team