using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Pomelo.DotNetClient { internal class UTF8BytesCache { public static readonly UTF8BytesCache Instance = new UTF8BytesCache(); private readonly Dictionary cache = new Dictionary(); private UTF8BytesCache(){} public byte[] GetBytes(string str) { lock(cache) { byte[] ret; if (cache.TryGetValue(str, out ret)) { return ret; } ret = Encoding.UTF8.GetBytes(str); cache.Add(str, ret); return ret; } } } }