private static void InitPy() { if (_search == null) { lock (lockObj) { if (_search == null) { var ass = typeof(WordsHelper).Assembly; #if NETSTANDARD2_1 Stream sm = ass.GetManifestResourceStream("ToolGood.Words.Pinyin.dict.Pinyin.dat.br"); #else Stream sm = ass.GetManifestResourceStream("ToolGood.Words.Pinyin.dict.Pinyin.dat.z"); #endif var sm12 = Decompress(sm); BinaryReader reader = new BinaryReader(sm12); _pyName = new Dictionary <string, ushort[]>(); var length = reader.ReadInt32(); for (int i = 0; i < length; i++) { var key = reader.ReadString(); var count = reader.ReadInt32(); var ubs = reader.ReadBytes(count); _pyName.Add(key, ByteArrToUint16Arr(ubs)); } length = reader.ReadInt32(); _pyShow = new string[length]; for (int i = 0; i < length; i++) { _pyShow[i] = reader.ReadString(); } length = reader.ReadInt32(); var bs = reader.ReadBytes(length); _pyIndex = ByteArrToUint16Arr(bs); length = reader.ReadInt32(); bs = reader.ReadBytes(length); _pyData = ByteArrToUint16Arr(bs); length = reader.ReadInt32(); bs = reader.ReadBytes(length); _wordPyIndex = ByteArrToIntArr(bs); length = reader.ReadInt32(); bs = reader.ReadBytes(length); _wordPy = ByteArrToUint16Arr(bs); var search = new WordsSearchEx(); search.Load(reader); reader.Close(); sm.Close(); _search = search; } } } }
public static void ClearCache() { lock (lockObj) { if (_pyName != null) { _pyName.Clear(); _pyName = null; } _pyShow = null; _pyIndex = null; _pyData = null; _wordPyIndex = null; _wordPy = null; if (_search != null) { _search.Dispose(); _search = null; } GC.Collect(); } }