A
A
Alexey Smirnov2017-11-08 15:57:45
.NET
Alexey Smirnov, 2017-11-08 15:57:45

How to optimize memory usage when writing one-dimensional arrays to a list?

Hello.
My program loops about a billion one-dimensional arrays into a list.

List<string[]> arrList = new List<string[]>();

// Тело цикла повторяющееся много раз:
{
    string[] arr = new string[5];

    arr[0] = "некоторое целое число" + "";
    arr[1] = "некоторое целое число" + "";
    arr[2] = "некоторое целое число" + "";
    arr[3] = "некоторая строка";
    arr[4] = "некоторая строка";

    arrList.Add(arr);
}

In the elements of the array, I write both strings and integers (which I then cast to the string type). The number of loop iterations is not known in advance (the number of iterations varies).
When executed, the program takes up a lot of RAM.
What could be done to reduce the consumption of RAM?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrDywar Pichugin, 2017-11-08
@ERAFY

https://www.ozon.ru/context/detail/id/23816449/
https://habrahabr.ru/post/260047/ - 2) The minimum size of an instance of a reference type in memory.
An array occupies a non-separable piece of memory.
An array of integers stores the values ​​of these numbers in its cells.
An array of strings stores in its cells the addresses of strings located elsewhere in memory.
Read about generations, assembly thresholds.
+ https://blogs.msdn.microsoft.com/ericlippert/2010/... The Truth About Value Types

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question