public T GetInstance() { var idt = Thread.CurrentThread.ManagedThreadId; Queue <T> q; if (!ht.ContainsKey(idt)) { q = new Queue <T>(); locker.Lock(); ht.Add(idt, q); locker.Unlock(); } else { q = ht[idt]; } T obj = null; if (q.Count > 0) { obj = q.Dequeue(); } return(obj); }
public static T Get() { var idt = Thread.CurrentThread.ManagedThreadId; Dictionary <Type, Queue <T> > dic; if (!ht_glob.ContainsKey(idt)) { dic = new Dictionary <Type, Queue <T> >(); locker_glob.Lock(); ht_glob.Add(idt, dic); locker_glob.Unlock(); } else { dic = ht_glob[idt]; } T obj = null; if (dic.ContainsKey(typeof(T))) { var q = dic[typeof(T)]; if (q.Count > 0) { obj = q.Dequeue(); } } return(obj); }
// Создает новую страницу public int Alloc() { var page = deleted.Pop(); //var page = 0; //if (deleted.Count > 0) //{ // page = deleted.Pop(); //} if (page == 0) { page = AddCount(1); if (HeaderSize + pageSize * Count >= length) { try { locker.Lock(); if (HeaderSize + pageSize * Count >= length) { length = HeaderSize + pageSize * Count * 2; stream.SetLength(length); } } finally { locker.Unlock(); } } } return page; }
// Создание нового элемента long CreateItem(int len) { try { locker.Lock(); var c = vars.Length; vars.Length += len; return(c); } finally { locker.Unlock(); } }