Fifo :访问其中的所有元素
Fifo : acces all elements in it
我的问题很简单,我使用的是眼动追踪设备,它大约每 30 毫秒发送一次注视位置。因此,每 30 毫秒更新一个变量 smoothedCoordinates
。
我想使用 smoothedCoordinates
的最后 X 个(例如 10 个)值来确定用户正在查看的屏幕上的区域。
为此,我必须将 smoothedCoordinates
的这些值存储在一个容器中,并对其进行处理以确定区域(通过获取这些 X 值的 xmin、xmax、ymin、ymax)
.
我考虑过使用 FIFO,每次更新变量时,我都会将值推到 fifo 的前面并弹出后面的值,在这种情况下,我的 FIFO 将始终是相同的大小。
但是是否可以直接访问 FIFO 的所有元素而不弹出它们?
我在网上搜了一下好像只能加入第一个元素和最后一个元素?
.
如果无法使用 FIFO 来完成,是否有其他容器可以满足我的需要?
您可以只使用标准数组并为其提供类似 FIFO 的功能,如下所示
char array[20];
// prepend the array and cut off the last value
for (int i = 19 ; i >= 0 ; i--)
{
// ignore the last element, so it gets overwritten
if (i != 19) array[i+1] = array[i];
}
// add the new value to the array at the now available 1st index
array[0] = firstElement[0];
我的问题很简单,我使用的是眼动追踪设备,它大约每 30 毫秒发送一次注视位置。因此,每 30 毫秒更新一个变量 smoothedCoordinates
。
我想使用 smoothedCoordinates
的最后 X 个(例如 10 个)值来确定用户正在查看的屏幕上的区域。
为此,我必须将 smoothedCoordinates
的这些值存储在一个容器中,并对其进行处理以确定区域(通过获取这些 X 值的 xmin、xmax、ymin、ymax)
.
我考虑过使用 FIFO,每次更新变量时,我都会将值推到 fifo 的前面并弹出后面的值,在这种情况下,我的 FIFO 将始终是相同的大小。
但是是否可以直接访问 FIFO 的所有元素而不弹出它们? 我在网上搜了一下好像只能加入第一个元素和最后一个元素?
.
如果无法使用 FIFO 来完成,是否有其他容器可以满足我的需要?
您可以只使用标准数组并为其提供类似 FIFO 的功能,如下所示
char array[20];
// prepend the array and cut off the last value
for (int i = 19 ; i >= 0 ; i--)
{
// ignore the last element, so it gets overwritten
if (i != 19) array[i+1] = array[i];
}
// add the new value to the array at the now available 1st index
array[0] = firstElement[0];