(f0d812055) v0.9.9.0

This commit is contained in:
Joonas Rikkonen
2020-04-23 19:19:37 +03:00
parent b647059b93
commit ac37a3b0e4
391 changed files with 15054 additions and 5420 deletions
@@ -9,31 +9,36 @@ namespace Steamworks
{
public const int MaxStringSize = 1024 * 32;
private static object mutex = new object();
private static IntPtr[] MemoryPool;
private static int MemoryPoolIndex;
public static unsafe IntPtr TakeMemory()
{
if ( MemoryPool == null )
IntPtr take = IntPtr.Zero;
lock (mutex)
{
//
// The pool has 5 items. This should be safe because we shouldn't really
// ever be using more than 2 memory pools
//
MemoryPool = new IntPtr[5];
if (MemoryPool == null)
{
//
// The pool has 5 items. This should be safe because we shouldn't really
// ever be using more than 2 memory pools
//
MemoryPool = new IntPtr[5];
for ( int i = 0; i < MemoryPool.Length; i++ )
MemoryPool[i] = Marshal.AllocHGlobal( MaxStringSize );
for (int i = 0; i < MemoryPool.Length; i++)
MemoryPool[i] = Marshal.AllocHGlobal(MaxStringSize);
}
MemoryPoolIndex++;
if (MemoryPoolIndex >= MemoryPool.Length)
MemoryPoolIndex = 0;
take = MemoryPool[MemoryPoolIndex];
((byte*)take)[0] = 0;
}
MemoryPoolIndex++;
if ( MemoryPoolIndex >= MemoryPool.Length )
MemoryPoolIndex = 0;
var take = MemoryPool[MemoryPoolIndex];
((byte*)take)[0] = 0;
return take;
}