Announcement

Collapse
No announcement yet.

Speed of writing to the file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Speed of writing to the file

    Hi

    in old PB3.5 i used MAP statement to speed up writing numbers
    to the disk using PUT and then reading them back by GET - it worked well, much
    faster than ordinary PRINT.

    I've tested PRINT to Sequential and Binary files (Random is actually
    slower due to string conversions) and the speed is about the same.

    As the other operations of PB/DLL are lightning fast,
    printing to the file is the part of my program
    which slows down app considerably (talking of Megs of numbers).

    Any suggestions

    Branko



    ------------------
    http://www.fg.uni-mb.si/lak/ocean


    Structural Engineering Software OCEAN2006
    Slovenia

    #2
    Since you could be using non-sequential files, why not use PUT and/or PUT$ ? You can use these to write large "blocks" of data in a single operation.

    Also note that a large part of the time a "write" operation takes is the O/S itself... writing to disk takes a finite amount of time, etc.

    Son to choose the best strategy, can you tell us how these numbers formatted? FOr example, if the file is only to store numbers then instead of writing plain text to the file, could could write binary representations instead. For example, a LONG variable will occupy 4 bytes regardless of it's actual numeric value.

    If this method is satisfactory for you, then you can write a whole numeric array in a single write operation too. For example:
    Code:
    ' Pseudocode
    DIM A&(1:1000000) 
    DIM B AS STRING PTR * 4000000 ' 4000000 = 1000000 * LEN(long integer)
    ...fill the A&() array here
    B = VARPTR(A&(1)) ' the address of the 1st item in the array
    OPEN "FILENAME.DAT" FOR BINARY LOCK READ WRITE AS #1
    PUT$ #1, @B
    CLOSE #1
    Random is actually slower due to string conversions)
    That effect has to be a direct result of your implementation, not the write operation itself.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


      #3
      Lance,

      i managed to write huge file as you suggested,
      now i need to read it back. (GET #1, @B ???)
      Pease give me a simple code for it.
      Thanks
      Branko

      ------------------
      http://www.fg.uni-mb.si/lak/ocean


      Structural Engineering Software OCEAN2006
      Slovenia

      Comment


        #4
        Branko, take a look at the GET$ statement in the help file...

        GET$ #FileNum, ByteCount, StringVariable

        Code:
        ' Pseudocode
        DIM A&(1:1000000), C$
        OPEN "FILENAME.DAT" FOR BINARY LOCK READ WRITE AS #1
        GET$ #1, 4000000, C$
        POKE$ VARPTR(A&(1)), C$
        CLOSE #1

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


          #5
          Lance,

          what is the dimension of C$ ?

          Branko

          ------------------
          http://www.fg.uni-mb.si/lak/ocean


          Structural Engineering Software OCEAN2006
          Slovenia

          Comment


            #6
            C$ = String$( Lof( #1 ), 0 )



            ------------------
            [email protected]
            hellobasic

            Comment


              #7
              What is the max value of x if dim b as string ptr*x

              ------------------

              Comment


                #8
                Well, string * nn is VERY undynamic.
                Are you sure you want to use it in these cases?

                I used a simple dynamic string and prefilled it with chr$(0) and poked the data to it's target.
                This is because Get$ can't handle anything other than strings while the native api can(must) fill a memory block in one pass.

                To bad..


                ------------------
                [email protected]
                hellobasic

                Comment

                Working...
                X
                😀
                🥰
                🤢
                😎
                😡
                👍
                👎