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 thisListwill shrink or the capacity (memory) of the List is still there and no memory allocation when I callList.AddRange()after theClear()? - List.Insert() will make the List larger or it just replace the existing item?
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.