简体   繁体   中英

which data structure is good for temporary big binary data storage?

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:

  1. which structure is good for this purpose? byte[10MB], List<bytes>(10MB), List<MyStruct>(24000), or ...?
  2. how to quickly wipe out the data (not List.Clear(), just set the value to 0) for List or array?
  3. 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()?
  4. List.Insert() will make the List larger or it just replace the existing item?

You will have to describe what you are doing more to give better answers but it sounds like you are worried about efficiency/perf so

  1. byte[]
  2. no need to clear the array, just keep track of where the 'end' of your current cycle is
  3. n/a
  4. n/a
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
{
    Do stuff
} // the using ensures proper simple disposal occurs here so you don't have to worry about cleaning up.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM