/// <summary> /// 分配数组 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="length"></param> /// <returns></returns> public static T[] GlobalAllocateArray <T>(int length) { ArrayPoolArg args = GlobalAllocate <ArrayPoolArg>(); args.length = length; var result = GlobalAllocate <T[]>(args); GlobalRecyle(args); return(result); }
/// <summary> /// 创建 /// </summary> /// <param name="arg"></param> /// <returns></returns> protected override T[] CreatNew(IEventArgs arg) { ArrayPoolArg len = arg as ArrayPoolArg; if (len != null) { return(new T[len.length]); } return(null); }
/// <summary> /// 获取 /// </summary> /// <param name="arg"></param> /// <returns></returns> public override T[] Get(IEventArgs arg = null) { ArrayPoolArg len = arg as ArrayPoolArg; if (len == null) { return(null); } int length = len.length; using (LockWait wait = new LockWait(ref lockParam)) { T[] t; if (pool.Count > 0 && _lengthqueue.Contains(length)) { Queue <T[]> queue = Framework.GlobalAllocate <Queue <T[]> >(); while (_lengthqueue.Peek() != length) { _lengthqueue.Dequeue(); queue.Enqueue(pool.Dequeue()); } t = pool.Dequeue(); while (pool.Count != 0) { queue.Enqueue(pool.Dequeue()); } int _count = queue.Count; for (int i = 0; i < _count; i++) { var tmp = queue.Dequeue(); int _len = tmp.Length; _lengthqueue.Enqueue(_len); pool.Enqueue(tmp); } Framework.GlobalRecyle(queue); } else { t = CreatNew(arg); OnCreate(t, arg); } OnGet(t, arg); return(t); } }