Page 1 of 6 123 ... LastLast
Results 1 to 10 of 52

Thread: ARRAY-ideas

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171

    ARRAY-ideas

    not a completely new idea (mentioned already in some other thread) but i would like to use the powers of Array Scan on data stored at heap-memory.

    How? Nearly the same way it works for arrays of dynamic strings currently. As far as i know a dynamic-string-array is just an array of stringpointers - right?

    I want to have an array of heap-pointers and scan the content of the pointed heap-areas.
    small example:

    DWord myPtrs = HEAP_AllocByStr(MKDWD$( _
              HEAP_AllocByStr("this"), _
              HEAP_AllocByStr("is an"), _
              HEAP_AllocByStr("array")  )      )
     
    Dim vPtr(HEAP_Size(myPtrs)/4) As DWord At myPtrs
    
    ' tell somehow its an array of pointers
    ' so i simply insert keyword Ptr here:
     
    PrintL Array Ptr Scan vPtr, Collate Ucase, = "ARRAY"
    
    ' should print 3 now
    
    PS. if a pointer contains 0 it should not throw error-
    and btw. change the behaviour of heap-memory and disable allocating sizes of less than 1 byte/ empty strings!

    ________________________________________________________________________

    Oh yes- another Array-idea were to have some way to loop through all elements of an array without the need of additional counter-variables.
    something alike
    With [Each Element Of] Array myArray
    '...do something...
    ' would be limited to arrays of udt only
    End With
    
    
    ' or another way:
    For Array myArray
      ' now myArray is an overlay at current element!
      ' (no limitation as above, so can use arrays of byte, long etc)
    Next
    
    (see more detailed examples for the second way here)
    Last edited by ReneMiner; 06-09-2014 at 16:25.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    Rene,

    I can only imagine what you could do with thinBASIC if you had access to the source. Maybe it's time Eros opens the door to serious advocates of the language. If that isn't a choice Eros is willing to make, you should find yourself an open source project and make these contributions count.

    John
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    @John,
    it is admirable how you always try to bring people on your side every time someone suggest new features not directly present into a programming language.
    I hope you are payed for this job.
    Well done


    @Rene,
    I will check if I can add the first request. It is very very specific command. I would like something more general to be used by the average programmer. Will see.
    Regarding the second request, I already started a FOREACH command but not yet finished.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    thanks for your reply... makes me feel tB is collecting energy for an upcoming boost in future. Actually the first (Array Scan)-request is the more important one to me- there a quite a few ways to loop through an array available already - the suggest was more because it's possible and fits the topic.

    The other thing - inbetween the lines - seems the most important to me - make Heap_Size < 1 unavailable please. I always use Heap_Size to detect if Heap at a certain pointer exists at all since there's no Heap_Exists and if a Heap_Size can not be below 1 then it would not be necessary to check any else than size to test the existence/validity of some heap-memory.
    to delete some old memory i check mostly like that since there's no other method:
    if Heap_Size(x) then 
     Heap_Free(x)
     x = 0
    endif
    
    but if Heap_Size(x) = 0 then i have a lost orphan pointer and some 0-len-memory-block stays allocated. So to me seems very important that Heap_Size of 0 Bytes are not accepted/allocated and simply return 0 on Heap_Alloc/Heap_ReAlloc/Heap_AllocByStr if size of data < 1
    Last edited by ReneMiner; 08-09-2014 at 18:03.
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    @John,
    it is admirable how you always try to bring people on your side every time someone suggest new features not directly present into a programming language.
    I hope you are payed for this job.
    Well done
    Excuse me but where did you read me asking Rene to join me or the Script BASIC project? I said find an open source project. Please don't start reading between the lines. There is already enough of that going around.

    A simple answer how you feel about opening the source would have been sufficient.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Ciao Renč,

    as a starter, please find here enclosed an updated thinCore.dll.
    To install just unzip it into \thinBasic\ directory replacing your current thinCore.dll.

    New syntax for HEAP_AllocByStr is the following:
    ptr = HEAP_AllocByStr(String [, AllowEmptyStringAllocation])

    In case of empty string, now allocation will take place (function will return zero) unless optional param "AllowEmptyStringAllocation" will be %TRUE


    Also implemented Heap_End as requested at http://www.thinbasic.com/community/p...hp?issueid=471


    Actually I'm finishing to develop and document two new thinBasic modules: Excel and AdoDB. Quite excited about that.
    As soon as I will finish (documentation included) I will publish thinBasic 1.9.14. Around end of next week.

    In the meantime I will think about your recent requests. "Array Ptr Scan ..." is quite easy, maybe I will be able to include in this round.

    Ciao
    Eros
    Attached Files Attached Files
    Last edited by ErosOlmi; 09-09-2014 at 23:31.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Ciao again Renč.

    Attached a new thinCore.dll where I've developed a preliminar version of your ARRAY SCAN ... PTR ... request.

    Syntax is the following (PTR just after array name):
    Uses "console"
    
    '---Allocate a string that is a sequance of some DWORDs.
    '---Each DWORD represents a PTR to a heap memory area where a string is allocated
    DWord myPtrs = HEAP_AllocByStr( _
                                    MKDWD$( _
                                            HEAP_AllocByStr("this")   , _
                                            HEAP_AllocByStr("is an")  , _
                                            HEAP_AllocByStr("array")  , _
                                            HEAP_AllocByStr("of")     , _
                                            HEAP_AllocByStr("some")   , _
                                            HEAP_AllocByStr("strings")  _
                                          ) _
                                   ) 
    
    
    '---Define a virtual array over-imposing its structure to the previous allocated pointer
    Dim vPtr(HEAP_Size(myPtrs)/SizeOf(DWord)) As DWord At myPtrs
     
    '---Now scan that area using the new PTR option.
    '---PTR tells to ARRAT SCAN that the DWORD is in reality a pointer to some memory area
    '---where to find a heap allocation of a string to be used for comparison.   
    '---ATTENTION: this will work only for DWORD arrays!!!!!!!!!!!!!!!!!!!!!!!
    PrintL Array Scan vPtr Ptr, Collate Ucase, = "SOME"
    
    
    PrintL "Press any key"
    WaitKey
    
    Let me know if you find any bug. I didn't make much tests.

    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    cooool - very excited - it feels like being a child having birthday
    - still testing and trying -

    Heap_End also very nice working - now can virtually go "For Each" without the need of allocating additional variables nor calculations

    Uses "console"
     
    DWord myPtrs = HEAP_AllocByStr( _
                                    MKDWD$( _
                                            HEAP_AllocByStr("this")   , _
                                            HEAP_AllocByStr("is an")  , _
                                            HEAP_AllocByStr("array")  , _ 
                                            HEAP_AllocByStr("", TRUE) , _
                                            HEAP_AllocByStr("")       , _
                                            HEAP_AllocByStr("some")   , _
                                            HEAP_AllocByStr("strings")  _
                                          ) _
                                   )
       
    'test Heap_End
    Dim vSurf As DWord At myPtrs
    
    While VarPtr(vSurf) < Heap_End(myPtrs)
      PrintL Hex$(vSurf,8) & " : " & HEAP_Get(vSurf)
      SetAt( vSurf, VarPtr(vSurf) + SizeOf(vSurf))
    Wend
    
    PrintL $CRLF & Repeat$(42, "*")
    PrintL $CRLF & "Any key to end"
    WaitKey
    
    Last edited by ReneMiner; 10-09-2014 at 09:38.
    I think there are missing some Forum-sections as beta-testing and support

  9. #9
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171

    another test... and some Error

    Got an Error! But not related to the current topic but while experimenting with new tB-functions.
    This is my testing script, requires the heap-unit below and thinCore.dll above anyway since the unit makes use of the new Array Scan Ptr-functionality


    Uses "console"
    #INCLUDE "Heap.tBasicU"
          
    ' some simple udt for test
    Type t_vec3d
      X As Double
      Y As Double
      Z As Double
      SetPos As Function
    End Type            
    
    Function t_Vec3d.SetPos(ByVal X As Double, ByVal Y As Double, ByVal Z As Double)
      Me.X = X
      Me.Y = Y
      Me.Z = Z
    End Function
     
    ' ---------------
     
    Dim foo As Heap
    
    ' create some space to store different things at foo
    foo.AllocLike("Heap", 3)
    
    ' first heap at foo shall contain a string
    Dim vHeap Like foo.GetType At foo.pData
    vHeap.Be("Hello World", "String")
    
    ' next heap at foo shall contain some longs
    SetAt(vHeap, VarPtr(vHeap) + SizeOf(vHeap))
    vHeap.Be(MKL$(1,2,3,4,5), "Long")
    
    ' next heap at foo shall contain 3 vecs
    SetAt(vHeap, VarPtr(vHeap) + SizeOf(vHeap))
    vHeap.allocLike("t_Vec3d", 3)
      ' fill in some udt-data 
      Dim vVec Like vHeap.GetType At vHeap.pData
      vVec.SetPos(1.1, 1.2, 1.3)
      SetAt( vVec, VarPtr(vVec)+ SizeOf(vVec) )
      vVec.SetPos(2.1, 2.2, 2.3)
      SetAt( vVec, VarPtr(vVec)+ SizeOf(vVec) )
      vVec.SetPos(3.1, 3.2, 3.3)
      
    ' now reset to first heap
    SetAt( vHeap, foo.pData )
    While VarPtr(vHeap) < foo.GetEnd 
    
      PrintL "Type is " & vHeap.GetType
      
      ' replace below
      '  "HEAP_Get(vHeap.pType)" with "vHeap.GetType()" to have error
      'the following line is the one:
      Select Case HEAP_Get(vHeap.pType)
        Case "STRING"
          PrintL "contains :" & vHeap.Is  
        Case "LONG"
          Dim vLong As Long At vHeap.pData
          While VarPtr(vLong) < vHeap.GetEnd
            PrintL vLong
            SetAt(vLong, VarPtr(vLong) + SizeOf(Long))
          Wend
        Case "T_VEC3D"
          SetAt(vVec, vHeap.pData)
          While VarPtr(vVec) < vHeap.GetEnd
            PrintL "X:" & vVec.X
            PrintL "Y:" & vVec.Y
            PrintL "Z:" & vVec.Z
            
            SetAt(vVec, VarPtr(vVec) + SizeOf(vVec))
          Wend
      End Select
      ' push forward to next heap  
      SetAt(vHeap, VarPtr(vHeap) + SizeOf(vHeap) )
    Wend
    
    PrintL $CRLF & Repeat$(42, "*")
    PrintL $CRLF & "Any key to end"
    WaitKey
    
    check line 53 of the script.
    Select Case [some type-function-result]
    
    results in crash, no matter if parenthesis used or not. I don't know if that is always the case since i discovered this as a reason of error for the first time
    Attached Files Attached Files
    Last edited by ReneMiner; 10-09-2014 at 11:04.
    I think there are missing some Forum-sections as beta-testing and support

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Rene,

    I think the crash is related to the fact I never adjusted
    SELECT CASE <...>
    when <...> is a UDT function.

    When SELECT CASE <...> is fired, ThinBASIC try to understand if the next expression (the one inside <...>) is a numeric expression or a string expression.
    After that it is able to know that all internal CASE ... are one type or the other.

    My idea is that direct UDT functions in a SELECT statements are not supported and for this reason it does not know that vHeap.GetType will return a string.

    It should be an easy FIX but ...
    Actually I'm still at work after 14 hours working.
    I still have 1 hour drive at home.
    If I will have the forces I will check this night or (maybe) tomorrow, sorry.

    Ciao
    Eros
    Last edited by ErosOlmi; 10-09-2014 at 20:24.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 1 of 6 123 ... LastLast

Similar Threads

  1. OOP ideas
    By ErosOlmi in forum Suggestions/Ideas discussions
    Replies: 13
    Last Post: 26-08-2013, 20:26
  2. Ideas for dynamic Array-constructor on the fly
    By ReneMiner in forum Suggestions/Ideas discussions
    Replies: 0
    Last Post: 16-07-2013, 08:53
  3. copy array of UDT to another array in one step?
    By ReneMiner in forum thinBasic General
    Replies: 3
    Last Post: 02-11-2012, 01:15
  4. More Ideas
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 3
    Last Post: 27-10-2012, 14:47

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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