{
internal class IntPtrPool
{
- private System.Collections.Generic.Stack<IntPtr> pool = new System.Collections.Generic.Stack<IntPtr>();
+ private Queue<IntPtr> ptrQueue = new Queue<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)
+ public IntPtrPool(CreatePtrCallback createPtrCb, DeletePtrCallback deletePtrCb)
{
this.createPtrCb = createPtrCb;
+ this.deletePtrCb = deletePtrCb;
+ pools.Add(this);
}
public IntPtr GetPtr()
{
IntPtr ret = IntPtr.Zero;
- if (0 == pool.Count)
+ if (0 == ptrQueue.Count)
{
if (null == createPtrCb)
{
}
else
{
- ret = pool.Pop();
+ ret = ptrQueue.Dequeue();
}
return ret;
public void PutPtr(IntPtr ptr)
{
- pool.Push(ptr);
+ ptrQueue.Enqueue(ptr);
+ }
+
+ public void ClearPtrs()
+ {
+ while (ptrQueue.Count > 0)
+ {
+ var ptr = ptrQueue.Dequeue();
+ deletePtrCb?.Invoke(ptr);
+ }
}
}
}
{
if (null == ptrPool)
{
- ptrPool = new IntPtrPool(CreateEmptryPtr);
+ ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
}
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);
+ ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
}
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);
+ ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
}
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);
+ ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
}
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);
+ ptrPool = new IntPtrPool(CreateEmptryPtr, DeletePtr);
}
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.