{
internal class IntPtrPool
{
- private Queue<IntPtr> ptrQueue = new Queue<IntPtr>();
+ private System.Collections.Generic.Stack<IntPtr> pool = new System.Collections.Generic.Stack<IntPtr>();
private CreatePtrCallback createPtrCb;
- private DeletePtrCallback deletePtrCb;
-
- private static List<IntPtrPool> pools = new List<IntPtrPool>();
public delegate IntPtr CreatePtrCallback();
- public delegate void DeletePtrCallback(IntPtr ptr);
-
- public static void ClearPools()
- {
- foreach (var pool in pools)
- {
- pool.ClearPtrs();
- }
- }
- public IntPtrPool(CreatePtrCallback createPtrCb, DeletePtrCallback deletePtrCb)
+ public IntPtrPool(CreatePtrCallback createPtrCb)
{
this.createPtrCb = createPtrCb;
- this.deletePtrCb = deletePtrCb;
- pools.Add(this);
}
public IntPtr GetPtr()
{
IntPtr ret = IntPtr.Zero;
- if (0 == ptrQueue.Count)
+ if (0 == pool.Count)
{
if (null == createPtrCb)
{
}
else
{
- ret = ptrQueue.Dequeue();
+ ret = pool.Pop();
}
return ret;
public void PutPtr(IntPtr ptr)
{
- ptrQueue.Enqueue(ptr);
- }
-
- public void ClearPtrs()
- {
- while (ptrQueue.Count > 0)
- {
- var ptr = ptrQueue.Dequeue();
- deletePtrCb?.Invoke(ptr);
- }
+ pool.Push(ptr);
}
}
}
{
if (null == ptrPool)
{
- ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
+ ptrPool = new IntPtrPool(CreateEmptryPtr);
}
return ptrPool;
return Interop.Vector3.NewVector3();
}
- private static void DeletePtr(IntPtr ptr)
- {
- var swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, ptr);
- Interop.Vector3.DeleteVector3(swigCPtr);
- }
-
internal static new void Preload()
{
// Do nothing. Just call for load static values.
{
if (null == ptrPool)
{
- ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
+ ptrPool = new IntPtrPool(CreateEmptryPtr);
}
return ptrPool;
return Interop.Vector2.NewVector2();
}
- private static void DeletePtr(IntPtr ptr)
- {
- var swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, ptr);
- Interop.Vector2.DeleteVector2(swigCPtr);
- }
/// <summary>
/// The constructor.
/// </summary>
{
if (null == ptrPool)
{
- ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
+ ptrPool = new IntPtrPool(CreateEmptryPtr);
}
return ptrPool;
return Interop.Vector2.NewVector2();
}
- private static void DeletePtr(IntPtr ptr)
- {
- var swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, ptr);
- Interop.Vector2.DeleteVector2(swigCPtr);
- }
-
internal static new void Preload()
{
// Do nothing. Just call for load static values.
{
if (null == ptrPool)
{
- ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
+ ptrPool = new IntPtrPool(CreateEmptryPtr);
}
return ptrPool;
return Interop.Vector3.NewVector3();
}
- private static void DeletePtr(IntPtr ptr)
- {
- var swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, ptr);
- Interop.Vector3.DeleteVector3(swigCPtr);
- }
-
internal static new void Preload()
{
// Do nothing. Just call for load static values.
{
if (null == ptrPool)
{
- ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
+ ptrPool = new IntPtrPool(CreateEmptryPtr);
}
return ptrPool;
return Interop.Vector4.NewVector4();
}
- private static void DeletePtr(IntPtr ptr)
- {
- var swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, ptr);
- Interop.Vector4.DeleteVector4(swigCPtr);
- }
-
internal static new void Preload()
{
// Do nothing. Just call for load static values.