Pool 적용 버그 잡는 중

This commit is contained in:
logonkhi
2025-06-27 17:50:23 +09:00
parent 935979a696
commit 750d38153d
32 changed files with 1977 additions and 218 deletions

View File

@@ -10,7 +10,7 @@ namespace UVC.Data
public static class DataArrayPool
{
private static readonly ConcurrentQueue<DataArray> _pool = new ConcurrentQueue<DataArray>();
private static int _maxPoolSize = 500; // DataArray는 DataObject보다 수가 적을 것이므로 기본값 조정
private static int _maxPoolSize = 100; // DataArray는 DataObject보다 수가 적을 것이므로 기본값 조정
// --- 통계용 필드 ---
private static int _inUseCount = 0;
@@ -18,15 +18,16 @@ namespace UVC.Data
private static int _poolMisses = 0;
private static readonly object _statsLock = new object();
/// <summary>
/// 풀의 최대 크기를 설정합니다.
/// </summary>
/// <param name="size">설정할 최대 크기</param>
public static void SetMaxPoolSize(int size)
static DataArrayPool()
{
_maxPoolSize = size > 0 ? size : 500;
// maxPoolSize만큼의 DataObject 인스턴스를 미리 생성하여 풀에 추가합니다.
for (int i = 0; i < _maxPoolSize; i++)
{
_pool.Enqueue(new DataArray() { IsInPool = true });
}
}
/// <summary>
/// 풀에서 DataArray 객체를 가져옵니다. 풀이 비어있으면 새로 생성합니다.
/// </summary>
@@ -50,17 +51,16 @@ namespace UVC.Data
{
int oldSize = _maxPoolSize;
_maxPoolSize += 100; // 증가량 조정
Debug.Log($"DataArrayPool size automatically increased from {oldSize} to {_maxPoolSize}. Peak usage: {_peakUsage}");
//Debug.Log($"DataArrayPool size automatically increased from {oldSize} to {_maxPoolSize}. Peak usage: {_peakUsage}");
}
}
}
if(_peakUsage % 100 == 0) Debug.Log($"DataArrayPool stats: {GetStats()}");
//if(_peakUsage % 10 == 0) Debug.Log($"DataArrayPool stats: {GetStats()}");
if (fromPool)
{
array.IsInPool = false;
array.Reset();
}
return fromPool ? array : new DataArray();
}
@@ -93,7 +93,7 @@ namespace UVC.Data
/// <returns>풀 통계 (최대 사용량, 현재 사용량, 풀 비어있을 때 생성 횟수, 현재 풀 크기)</returns>
public static string GetStats()
{
return $"Peak Usage: {_peakUsage}, In Use: {_inUseCount}, Misses: {_poolMisses}, Pooled: {_pool.Count}, Max Size: {_maxPoolSize}";
return $"최대 사용량: {_peakUsage}, 현재 사용량: {_inUseCount}, 풀 비어있을 때 생성 횟수: {_poolMisses}, 현재 풀 크기: {_pool.Count}, Max Size: {_maxPoolSize}";
}
/// <summary>