Author Topic: Create large files FAST!  (Read 5163 times)

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Create large files FAST!
« on: January 30, 2021, 12:36:13 am »
Create a 4GB file in under a minute.


Code: QB64: [Select]
  1. a = "A"
  2.  
  3. OPEN "test111" FOR BINARY AS #1
  4.  
  5. SEEK #1, 4000000000
  6.  
  7. PUT #1, , a
  8.  
  9.  
  10.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Create large files FAST!
« Reply #1 on: January 30, 2021, 09:46:00 am »
LOL yeah but why? ;-))

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Create large files FAST!
« Reply #2 on: January 30, 2021, 10:15:16 am »
What is the purpose of this
Shuwatch!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Create large files FAST!
« Reply #3 on: January 30, 2021, 03:29:35 pm »
I guess some people just hate unused disk space; but I'm not one of them.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Create large files FAST!
« Reply #4 on: January 30, 2021, 03:57:38 pm »
Hey do you think that may stop MS updates?

Sorry, disk full.  ;-))

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Create large files FAST!
« Reply #5 on: January 30, 2021, 05:36:05 pm »
Been there, tried that. Nice concept, but no. Apparently MS just searches out you non-G rated photos, and overwrites them with updates. Oh, unless you download those photos from an approved MS Store source. I don't know about you, but I cant' force myself to look at even one pic of Bill Gates in a Speedo, and that guy Ballmer, I don't make enough money anymore to afford that number of therapy sessions.

Actually, that's a great question. If it weren't for needed non-MS antivirus updates, it might be worth messing with. God knows all the usual methods to disable updates eventually fail to work anymore. Other than that, you just have to play Task Manager monitor, and kill those pesky Update and Update Orchestrator processes.

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Create large files FAST!
« Reply #6 on: January 30, 2021, 07:06:40 pm »
Why?

Well ahem . . . let me go back to the old DOS interrupts

http://www.ctyme.com/intr/rb-2799.htm

You set the "file pointer"  (using assembler)  beyond the end of a file and then WRITE zero bytes.

Yep it is possible to write zero bytes.   Then close the file.

After the write, the file is updated with the new file size.  So what was written ? actually nothing was written.   Writing zero bytes still updates the FAT (FAT NTFS etc)

That is why it takes very little time to create a large file that way

Under FAT32 the largest file size is 2 ^32 -1 bytes

However,   QB64 (and whatever QB45 had) can not write zero bytes.

Using PUT you gotta write  1 byte to make this work.

Quote
DIM a AS STRING
a = "A"
OPEN "test111" FOR BINARY AS #1
SEEK #1, 4000000000
PUT #1, , a
CLOSE

The "A" will be the last byte of the file. Why?  because the SEEK statement moves the file pointer to the 4,000,000,000 th byte position.

I'm not sure of the limits of the SEEK statement in QB64 but I imagine that really large files could be created this way.




« Last Edit: January 30, 2021, 07:31:34 pm by NOVARSEG »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Create large files FAST!
« Reply #7 on: January 30, 2021, 08:21:56 pm »
Yeah I guess if I want a 4 gig empty file then cool.
Shuwatch!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Create large files FAST!
« Reply #8 on: January 30, 2021, 08:24:27 pm »
Note: You don’t even need a SEEK to do this.

DIM a AS STRING
a = "A"
OPEN "test111" FOR BINARY AS #1
PUT #1, 4000000000, a
CLOSE
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Create large files FAST!
« Reply #9 on: January 30, 2021, 08:52:16 pm »

That's right, the second comma is for position

PUT #1, 4000000000, a

It must do the same thing as SEEK.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Create large files FAST!
« Reply #10 on: January 30, 2021, 10:21:53 pm »
File size  =  68,719,476,736

Took about 16 minutes

Quote
DIM a AS STRING
a = "A"
OPEN "test111" FOR BINARY AS #1
PUT #1, 2 ^ 36, a
CLOSE



Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Create large files FAST!
« Reply #11 on: January 30, 2021, 10:24:20 pm »
Let's do this! Feel free to test this:

Code: QB64: [Select]
  1. a = "A"
  2. OPEN "test111" FOR BINARY AS #1
  3. SEEK #1, 1024^4
  4. PUT #1, , a

OK but don't actually run it
« Last Edit: January 30, 2021, 10:29:50 pm by SpriggsySpriggs »
Shuwatch!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Create large files FAST!
« Reply #12 on: January 30, 2021, 10:55:16 pm »
1024  ^ 4 = 2 ^ 40 = about 1024GB  just over a Terabyte.    There is no telling what would happen.

Even if it worked, what would happen if an app tried to open the file?

« Last Edit: January 30, 2021, 11:03:04 pm by NOVARSEG »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Create large files FAST!
« Reply #13 on: January 30, 2021, 10:57:58 pm »
1024 ^ 4 is a Terabyte, with Microsoft data structure.
Shuwatch!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Create large files FAST!
« Reply #14 on: January 30, 2021, 11:04:03 pm »
to do it safely need bigger than a terabyte hard drive

 my computer would take about 4 hours

A huge file with a single "A" at the end!!!
« Last Edit: January 30, 2021, 11:10:47 pm by NOVARSEG »