ðCircular Queue(In Tracking Data)
Use List
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class CircularQueueManager : MonoBehaviour
{
public List<byte[]> circularQueue = null;
public int circularQueueLength = 10;
public int curIndex = 0;
public int preIndex = 0;
private void Awake()
{
if (circularQueue == null)
{
circularQueue = new List<byte[]>();
for (int i = 0; i < circularQueueLength; i++)
{
circularQueue.Add(new byte[] { });
}
}
}
public void setData(byte[] byteArr)
{
byte[] arr = new byte[byteArr.Length];
Array.Copy(byteArr, arr, byteArr.Length);
circularQueue[curIndex] = arr;
curIndex = curIndex == circularQueue.Count - 1 ? 0 : curIndex + 1;
preIndex = curIndex - 1;
preIndex = preIndex == -1 ? circularQueue.Count - 1 : preIndex;
}
public byte[] getData()
{
if (preIndex == curIndex)
{
return null;
}
byte[] data = circularQueue[preIndex];
return data;
}
}
Last updated