Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: some arrays goodies

Share/Bookmark
  1. #11
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,078
    Blog Entries
    2
    Rep Power
    10
    I'm working on it, slowly but I'm working.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  2. #12
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    47
    Posts
    1,213
    Blog Entries
    1
    Rep Power
    132
    I have another suggest for those who have a homogeneous array of numbers that's elements count is unknown in advance but the size altogether will not exceed 2GB.
    No redim needed if elements shall be added, all done by the powers of thinBasic.
    Use a string.
    How?
    Uses "console"
    
    ' this will store the numbers:
    Dim myNumericArray as String
    
    ' access the numbers virtually:
    Dim myNumber() as Number At 0
    
    Dim i As Long ' just to list our arrays elements
    
    ' add a few elements, type Ext equals Number, that's why MKE$:
    myNumericArray = MKE$(0.12345) ' the first element be 0.12345
    ' just append a bunch of new elements:
    myNumericArray &= MKE$(1,2,3,4,5)
    ' and some more
    myNumericArray &= MKE$(6.666, 7.777)
    
    ' now let's read what we have:
    ' put the virtual array onto the string:
    Redim myNumber(Strptrlen(Strptr(myNumericArray))/SizeOf(Number)) At Strptr(myNumericArray)
    
    ' list what we have
    For i = 1 to UBound(myNumber)
      PrintL i, myNumber(i)
    Next
    
    WaitKey
    
    Just an idea. Typed this on the mobile, not error-checked. Perhaps the $-sign is wrong on the phone? If so someone may correct it.
    But you could tell me if string reallocates faster than Redim
    Last edited by ReneMiner; 16-03-2017 at 21:30.
    Windows 10 on
    Desktop: Intel Core i5-3330 @3.0 GHz, 8 GB Ram, nVidia GeForce GT630 2 GB
    Laptop: Intel Core i3-4005U @1.7GHz, 8 GB Ram, nVidia GeForce 940M 2 GB


    The limit is Imagination

  3. #13
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,724
    Blog Entries
    3
    Rep Power
    685
    Rene,

    thank you for your example! This approach could be further mixed with stringBuilder to reach maximum efficiency.
    Each &= means reallocation in your case, while stringBuilder reallocates only when you reach its internal capacity, which keeps doubling


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  4. #14
    @Petr Schreiber,
    Could you please post an example with StringBuilder ?

  5. #15
    @kcvinu
    until Petr reply, i say i have tried string builder just recently, and it is very efficient, here its thread http://www.thinbasic.com/community/s...inBASIC-GitHub
    look the Petr example there
    while its page is here: https://github.com/petrSchreiber/thi...ngBuilder/wiki
    look more of its methods available
    it is genuine and in the github page is its source code
    to create it:
    'Dim stringBuffer As String
    Dim sb As StringBuilder
    sb = New StringBuilder()
    
    and to build big string from some words
    For i = 1 To 20000
    sb.Add("Appending is fine!")
    Next
    
    the result is instantaneous
    here is we save the big string to a file because the Console can't display more than a few thousands of charaters)
    note what in the string builder we copy to a usual string
    bigString = sb.ToString() to display it.
    Uses "StringBuilder", "Console", "File"
    
    Function TBMain()
    
    'Dim stringBuffer As String
    Dim bigString As String
    Dim sb As StringBuilder
    sb = New StringBuilder()
    
    Long i
    
    For i = 1 To 20000
    sb.Add("Appending is fine!")
    Next
    
    bigString = sb.ToString()
    
    FILE_Save("test.txt", bigString)
    
    PrintL "big string saved as file test.txt .... Press any key to quit..."
    
    WaitKey
    
    End Function
    
    Last edited by primo; 20-03-2017 at 07:14.

  6. #16
    @primo,
    Thanks for the example. Its really fast for creating and saving that 352 KB text file. I think the variable named Stringbuffer is useless in your code. Let me check the links you provide. Thanks again.
    Last edited by kcvinu; 19-03-2017 at 21:42.

  7. #17
    Thank you kcvinu for the notes.
    i have tried also to loop up to a million loops for the sentence of 20 characters. and using AddLine method (listed in page https://github.com/petrSchreiber/thi...ngBuilder/wiki ) which adds a new line after reading one string. in one second it saves about 21 MB txt file.
    but never try to open this big text file in notepad it will hang your computer. a good editor i see to open these big files is EmEditor
    https://www.emeditor.com/text-editor...s-up-to-248gb/
    but the notepad++ can open it ( https://notepad-plus-plus.org/download/ ) note that opening the files which have many new lines is easier than continuous file.
    Uses "StringBuilder", "Console", "File"
     
    Function TBMain()
     
    'Dim bigString As String
    Dim sb As StringBuilder
    sb = New StringBuilder()
     
    Long i
     
    For i = 1 To 1000000
    sb.AddLine("Appending is fine!!!")
    Next
     
    'bigString = sb.ToString()
     
    FILE_Save("test.txt", sb.ToString())'bigString)
     
    PrintL "big string saved as file test.txt .... Press any key to quit..."
     
    WaitKey
     
    End Function
    
    there are other things to discover yet. thanks for Petr and Eros for this jewel .
    Last edited by primo; 20-03-2017 at 07:12.

  8. #18
    @primo,
    Wow ! one million lines of text. Obviously it's a huge file. I am assuming that you might see your computer hung when you opened it in notepa. Am i right ?

  9. #19
    kcvinu wrote: I am assuming that you might see your computer hung when you opened it in notepa. Am i right ?
    in windows xp the notepad does not hung if we created the txt file using sb.AddLine even with slow performance , but it hung and freeze if we created the file with sb.Add ie as one line. to be sure the end of the file displayed add "finish":
    Click image for larger version. 

Name:	viewer.PNG 
Views:	12 
Size:	48.4 KB 
ID:	9663
    For i = 1 To 1000000
    sb.Add("Appending is fine!!!")
    Next
    sb.Add("finish")

    the universal viewer is able to load any file
    the freeware version of universal viewer is here:
    http://www.uvviewsoft.com/uviewer/download.htm

    but only EmEditor is able to show the 20 MB one line file as one line, when we move the cursor to the end of the file we see this
    ln 1 col 20000006
    ie line 1 column 20,000,006

  10. #20
    @primo,
    Thanks a lot for introducing Universal Viewer. Its a must have program.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. 3d arrays?
    By JosephE in forum thinDebug
    Replies: 2
    Last Post: 08-08-2010, 23:21
  2. Arrays
    By Charles Pegge in forum O2h Compiler
    Replies: 0
    Last Post: 17-03-2009, 16:09

Posting Permissions

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