Results 1 to 7 of 7

Thread: Difficulties when trying to sort a custom type array

  1. #1
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    65
    Posts
    40
    Rep Power
    5

    Difficulties when trying to sort a custom type array

    Hi,

    A you can see in enclosed file, I try to sort an array.
    This array contains members (10 in my example but more in reality) each member is
    type 
    'members
     end type
    
    defined.

    When I try to sort the array by the first member of the structure, the program crashes (see screenshots)

    This appears either with interpreted or bundled version.

    What's wrong ?

    Regards,

    Dany
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	screenshot.png 
Views:	30 
Size:	87.5 KB 
ID:	9805  
    Attached Files Attached Files

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,311
    Blog Entries
    2
    Rep Power
    10
    In general Array Sort is not able to recognize array of UDT (User Defined Type) data type.
    But it should not crash, just do a binary sort based of the binary data inside UDT element
    In your example it should sort based on binary data strings composed by 10 bytes ("sName" string) + 4 bytes (binary representation of DWord "SValue") + 4 bytes (binary representation of Long "sCount")

    I have to investigate why it crash

    Thanks for reporting
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,311
    Blog Entries
    2
    Rep Power
    10
    I found the problem and solved.

    But I do not like the solution I implemented because sorting an array of UDTs would require to:
    1. make a copy of the memory allocated by the UDT
    2. splitting into dynamic strings array
    3. sorting array
    4. putting back memory into the UDT


    I'm searching a clever solution.
    I asked into Power Basic compiler forum for some help:
    https://forum.powerbasic.com/forum/u...f-unknown-size
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  4. #4
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    65
    Posts
    40
    Rep Power
    5
    Quote Originally Posted by ErosOlmi View Post
    In general Array Sort is not able to recognize array of UDT (User Defined Type) data type.
    But it should not crash, just do a binary sort based of the binary data inside UDT element
    In your example it should sort based on binary data strings composed by 10 bytes ("sName" string) + 4 bytes (binary representation of DWord "SValue") + 4 bytes (binary representation of Long "sCount")

    I have to investigate why it crash

    Thanks for reporting
    Eros
    Hi Eros,

    This behaviour would fulfill my needs, because a previous check does not allow duplicate values in first field (string)

    Regards


    Dany

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,311
    Blog Entries
    2
    Rep Power
    10
    Please find attached thinCore.dll
    Unzip it under the following folders:
    • \thinBasic\
    • \thinBasic\thinAir

    replacing your current version

    I've fixed array sort for user defined type arrays in the "slow and dirty" way I've described above

    Let me know if it works

    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  6. #6
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    65
    Posts
    40
    Rep Power
    5
    Quote Originally Posted by ErosOlmi View Post

    Let me know if it works

    Ciao
    Eros
    No more crash !

    It works, but :

    Array Sort symbol_prg() ' empty strings first ,  then chars in ASCII order     OK for ascending
    Array Sort symbol_prg() , Descend '  give the same result.  DESCEND  seems to be ignored ?
    
    I did not test asfiles option

    Non UDT array keeps sorted OK

    Regards,


    Dany

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,311
    Blog Entries
    2
    Rep Power
    10
    Reality is that thinBasic was not sorting at all fixed buffers (strings, UDT, ...)
    So it is an area all to be constructed

    I will add missing part asap ad post new Core to test.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. Array Sort - once more...
    By ReneMiner in forum Suggestions/Ideas discussions
    Replies: 3
    Last Post: 20-12-2015, 13:23
  2. Array Sort- issue
    By ReneMiner in forum Core module
    Replies: 3
    Last Post: 04-11-2015, 00:41
  3. Replacing ARRAY SORT
    By MikeTrader in forum Power Basic
    Replies: 9
    Last Post: 28-08-2009, 22:57
  4. Array vs type optimization
    By MouseTrap in forum Power Basic
    Replies: 6
    Last Post: 04-03-2009, 11:05

Posting Permissions

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