Results 1 to 3 of 3

Thread: Copying a file from a range of bytes....

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126

    Angry

    Dear all,

    Making a program to copy a file to another file but only the specified range of bytes. IE: The first 4500k of a 10mb file etc... I've fiddled with some code, works fine, but rus extremely slow, im talking, 5 minutes to copy 1000k of data, anyone know of a more efficient way to copy a file using byte range, here's my code...

    Code:
    Dim TempChar as Byte
    Dim ByteLength as Long
    
    Open "input.dat" for Binary Access Read as #1
    Open "output.dat" for Binary Access Write as #2
    
    ByteLength = 4539139 'End of file or byte length, just over 4.5mb of the file
    
    'from start of file to end of marker/byte length...
    For x = 1 to ByteLength
        Get #1,, TempChar
        Put #2,, TempChar
    Next x
    
    Close #1
    Close #2
    Anyone know why it takes so god damn long to do something simple? its using on average of %6 CPU usage the rest is idle, therefore it aint the CPU causing probs. please help!

    Regards,

    Paul Rivoli
    ---------------------
    [email protected]
    http://members.dingoblue.net.au/~privoli

  2. #2
    Guest
    it is slow because the string is very long. speed is not directly relative to string length, try using several smaller strings, not more than 3000 characters at a time.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Ok, loading a varlen string is much faster, aslo use freefile so that you don't get invalid filenumbers
    Code:
    Dim Temp as string
    Dim ByteLength as Long
    f1=freefile
    Open "input.dat" for Binary Access Read as f1
    f2=freefile
    Open "output.dat" for Binary Access Write as f2
    
        Get f1,, Temp
        Put f2,, Temp
    
    Close f1
    Close f2
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width