public void CheckAPI_ReallocateTracer() { #if ENABLE_UNITY_COLLECTIONS_CHECKS string str = "1234567890--@@"; var NSL = new NativeStringList(Allocator.TempJob); NSL.Add(str); StringEntity entity = NSL[0]; bool effective_ref = true; for (int i = 0; i < 100; i++) { NSL.Add(str); try { Debug.Log($"add: {i}, entity: {entity.ToString()}, NSL [Size/Capacity] = [{NSL.Size}/{NSL.Capacity}]"); } catch (InvalidOperationException e) { effective_ref = false; Debug.Log("the reallocation of NativeStringList is detected by StringEntity. exception: " + e.Message); break; } } Assert.IsFalse(effective_ref); NSL.Dispose(); #else Debug.Log("this feature will be enabled when the macro 'ENABLE_UNITY_COLLECTIONS_CHECKS' is defined."); Debug.Log("it is not tested in current setting."); #endif }
public void CheckParseHex() { var str_native_big = new NativeStringList(Allocator.Temp); var str_native_lit = new NativeStringList(Allocator.Temp); this.CheckParseHexInt32(str_native_big, str_native_lit); this.CheckParseHexInt64(str_native_big, str_native_lit); this.CheckParseHexFloat32(str_native_big, str_native_lit); this.CheckParseHexFloat64(str_native_big, str_native_lit); str_native_big.Dispose(); str_native_lit.Dispose(); }
public void Dispose() { if (_allocated) { Data.Dispose(); IndexSeq.Dispose(); _name.Dispose(); _str_list.Dispose(); _tmp_name.Dispose(); _mark_list.Dispose(); _b64_decoder.Dispose(); _b64_decoded_bytes.Dispose(); _allocated = false; } }
public void Dispose(bool disposing) { if (disposing) { this.Complete(); this.DisposeHandle(); if (_info.Target->allocated) { _byteReader.Dispose(); _worker.Dispose(); _lines.Dispose(); _info.Target->allocated = false; } _info.Dispose(); } }
public void CheckAPI_StringEntity_IndexOf() { string str = "1234567890--@@G1234567890--@@@xxmhr1234567890--@@"; var NSL = new NativeStringList(Allocator.TempJob); NSL.Add(str); StringEntity entity = NSL[0]; // StringEntity.IndexOf(Char16) Assert.AreEqual(entity.IndexOf('6'), 5); Assert.AreEqual(entity.IndexOf('6', 10), 20); Assert.AreEqual(entity.IndexOf('x'), 30); Assert.AreEqual(entity.IndexOf('W'), -1); // not found // StringEntity.IndexOf(string) (= same implementation of IndexOf(StringEntity)) Assert.AreEqual(entity.IndexOf("@@x"), 28); Assert.AreEqual(entity.IndexOf("890-"), 7); Assert.AreEqual(entity.IndexOf("890-", 12), 22); Assert.AreEqual(entity.IndexOf("99"), -1); // not found NSL.Dispose(); }
private unsafe void GenerateImpl(Encoding encoding, int n, int d, float r) { _i_chara = 0; var sb = new StringBuilder(); Debug.Log(" >> write header >> "); //--- header sb.Append("#======================================="); sb.Append(_lf); sb.Append("# the belong area is a header data."); sb.Append(_lf); sb.Append("#======================================="); sb.Append(_lf); sb.Append("<@MARK>" + _delim + "Header"); sb.Append(_lf); sb.Append("n_total" + _delim + n.ToString()); sb.Append(_lf); sb.Append("d" + _delim + d.ToString()); sb.Append(_lf); sb.Append("r" + _delim + r.ToString()); sb.Append(_lf); sb.Append(_lf); // insert empty lines sb.Append(_lf); sb.Append(_lf); //--- generate random id sequence var id_Sequence = new NativeList <int>(n, Allocator.Persistent); id_Sequence.Clear(); for (int id = 0; id < n; id++) { id_Sequence.Add(id * d); } //int n_swap = (int)Math.Sqrt(n); int n_swap = n; var random = new System.Random(n_swap * d); for (int i_swap = 0; i_swap < n_swap; i_swap++) { int index = (int)(n * random.NextDouble() * 0.95); var tmp = id_Sequence[index]; id_Sequence.RemoveAtSwapBack(index); id_Sequence.Add(tmp); } Debug.Log(" >> write Ex Data >> "); //--- Ex data sb.Append("#======================================="); sb.Append(_lf); sb.Append("# the belong area is a Base64 encorded ext data."); sb.Append(_lf); sb.Append("#======================================="); sb.Append(_lf); sb.Append("<@MARK>" + _delim + "ExtData"); sb.Append(_lf); int byte_len = id_Sequence.Length * UnsafeUtility.SizeOf <int>(); var byte_Sequence = new NativeArray <byte>(byte_len, Allocator.Persistent); UnsafeUtility.MemCpy(byte_Sequence.GetUnsafePtr(), id_Sequence.GetUnsafePtr(), byte_len); var b64_Sequence = new NativeList <Char16>(Allocator.Persistent); var b64_Encoder = new NativeBase64Encoder(Allocator.Persistent); b64_Encoder.GetChars(b64_Sequence, byte_Sequence); for (int i = 0; i < b64_Sequence.Length; i++) { sb.Append(b64_Sequence[i]); } sb.Append(_lf); sb.Append("<@MARK>" + _delim + "ExtDataEnd"); sb.Append(_lf); sb.Append(_lf); byte_Sequence.Dispose(); b64_Sequence.Dispose(); b64_Encoder.Dispose(); Debug.Log(" >> write body >> "); //--- body sb.Append("#======================================="); sb.Append(_lf); sb.Append("# the belong area is a data body."); sb.Append(_lf); sb.Append("#======================================="); sb.Append(_lf); sb.Append("<@MARK>" + _delim + "Body"); sb.Append(_lf); var dummy_line = "# ---" + _delim + "dummy" + _delim + "line" + _delim + "--- #"; //--- write CharaData var NSL_tmp = new NativeStringList(Allocator.Persistent); using (StreamWriter writer = new StreamWriter(_path, false, encoding)) { int i = 0; _i_chara = i; while (i < n) { if (random.NextDouble() > r) { NSL_tmp.Clear(); int id = id_Sequence[i]; var chara_tmp = CharaDataExt.Generate(id, NSL_tmp); sb.Append(chara_tmp.ToString(_delim)); sb.Append(_lf); i++; _i_chara = i; //Debug.Log(" -- body [" + i.ToString() + '/' + n.ToString() + ']'); } else { sb.Append(dummy_line); sb.Append(_lf); } if (sb.Length > 4096) // 4k: page size { writer.Write(sb); sb.Clear(); } } if (sb.Length > 0) { writer.Write(sb); } } id_Sequence.Dispose(); NSL_tmp.Dispose(); _standby = true; }