哪种数据结构适用于临时大二进制数据存储?(which data structure is good for temporary big binary data storage?)

编程入门 行业动态 更新时间:2024-10-21 13:13:07
哪种数据结构适用于临时大二进制数据存储?(which data structure is good for temporary big binary data storage?)

计划有一个数据结构来将临时二进制数据存储在内存中进行分析。

数据的最大大小约为10MB 。

数据将一次添加在408 bytes的末尾。

没有搜索,检索这些临时二进制数据的操作。

数据将被清除,存储将被重新用于下一次分析。

问题:

哪种结构对此有好处? byte[10MB], List<bytes>(10MB), List<MyStruct>(24000), or ...? 如何快速清除数据(不是List.Clear(),只需将值设置为0)List或数组? 如果我说List.Clear(),这个List的内存将会缩小,或者当我在Clear()?之后调用List.AddRange()时,List的容量(内存)仍然存在并且没有内存分配Clear()? List.Insert()将使列表变大或只是替换现有的项目?

Plan to have a data structure to store temporary binary data in the memory for analysis.

The max size of the data will be about 10MB.

data will be added at the end 408 bytes at a time.

no search, retrieve operations on those temporary binary data.

data will be wipe out and the storage will be reused for next analysis.

questions:

which structure is good for this purpose? byte[10MB], List<bytes>(10MB), List<MyStruct>(24000), or ...? how to quickly wipe out the data (not List.Clear(), just set the value to 0) for List or array? If I say List.Clear(), the memory for this List will shrink or the capacity (memory) of the List is still there and no memory allocation when I call List.AddRange() after the Clear()? List.Insert() will make the List larger or it just replace the existing item?

最满意答案

如果您的数据通常具有相同的大小,并且始终小于特定大小,请使用字节数组。

创建一个字节[]和一个int,让你知道该缓冲区的“全部”部分的末尾停止,并且“空闲”部分开始的位置。 你永远不需要清除它; 只是改写了那里。 唯一的问题是如果您的数据有时是100 kb,有时是10 MB,有时比您原先计划的大一点。

尽管列表中的数据可以处理各种大小的数据,但列表的内存使用速度会更慢,而内存容量更大。

If your data is usually the same size, and always under a certain size, use a byte array.

Create a byte[], and a int that lets you know where the end of the "full" part of that buffer stops and the "free" part starts. You never need to clear it; just overwrite what was there. The only problem with this is if your data is sometimes 100 kb, sometimes 10 MB, and sometimes a bit larger than you originally planned for.

List will be slower to use and larger in memory, although they handle various sizes of data out of the box.

更多推荐

本文发布于:2023-07-08 20:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080245.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   数据结构   哪种   数据存储   data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!