Search Unity

Question FixedString Noob Question with Job System (No Entities)

Discussion in 'C# Job System' started by jGate99, Sep 30, 2020.

  1. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,938
    Hi there,

    Sorry for asking basic stuff but i did tried both forum search and google search but didnt find anyting that answers these questions, so i really appreciate someone who has experienced with this can answer these.

    - If im not mistaken, we can now have NativeList<FixedString>,

    So my question is;
    Can this approach works with JobSystem and BurstCompiler where ill have a NativeList<FixedString> of "english words" to perform string comparisons operations ?


    Thanks
     
  2. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    Yes. But you can't use string literals like "SomeName". Liternal=>FixString must be done outside of job.
    You can append format FixedStrings in job.
     
    jGate99 likes this.
  3. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,938
    I wont be using string literal inside the job, but FixedString itself, isnt it possible? like my example below


    Code (CSharp):
    1. struct ScrabbleJob : IJob
    2.     {
    3.        
    4.         [ReadOnly]
    5.         public NativeList<FixedString> EnglishWordsEnteredByUser;
    6.    
    7.         [ReadOnly]
    8.         public NativeHashSet<FixedString> EnglishWordsDictionary;
    9.  
    10.  
    11.         public NativeArray<bool> Result;
    12.  
    13.  
    14.         public void Execute()
    15.         {
    16.  
    17.             bool AllValid = true;
    18.            
    19.             for (int j = 0; j < EnglishWordsEnteredByUser.Count; j++)
    20.             {
    21.                 var currentWord = EnglishWordsDictionary[j];
    22.  
    23.                 if (EnglishWordsDictionary.Contains(currentWord) == false)
    24.                 {
    25.                     AllValid = false;
    26.                 }
    27.             }
    28.  
    29.             Result[0] = AllValid;
    30.         }
    31.     }
     
  4. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    That should work
     
    jGate99 likes this.
  5. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,938
    Thanks, and what should i use for saving english words of varying length, FixedString or NativeString?
     
  6. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    283
    Keep in mind that (according to the Unity Collections package changelog) NativeString is now deprecated in favor of FixedString. Currently you should use the FixedString variant that supplies you with enough character capacity for your needs.

    Here's a comment with some guidance from NativeString.gen.cs but probably applies to FixedString* too:
     
    jGate99 likes this.
  7. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,938
    Thanks, appreciate that :)
     
  8. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    jGate99 likes this.
  9. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,938
    There should be a Generic FixedString which takes space based on the word length as putting FixedString32 means i;ll be forced to save all the words 32 as its a NativeArray<FixedString32>. Or is there a better way?