As a solution, we discussed the one that efficiently uses available memory and sends the data to the database in a batch. Again, the batch size depends on the different preferences and memory availability of every programmer, the application requirements, and availability of resources.
Now, we have two options for storing the data temporarily in memory. In this article, we do not discuss data-modification techniques in the table when some record is not available in memory. Instead, we discuss the creation of new records on the fly and the improvement of the overall performance. Still, we can make our own strategy for updating and deleting on the basis of critical application requirements.
So, to hold the data temporarily in memory, we can use multi-dimensional arrays or jagged arrays. The question is: Which one is a better option?
Again, it depends on the requirements. If the number of rows is fixed, and we really require the same number of columns in each row, no doubt multi-dimensional arrays are the best option. This is because they save us from having to create a new instance of columns in each row every time. That saves the overheads to perform the allocation of memory, and also the overheads created by the dynamic nature of every row in the case of jagged arrays. But most of the time in real-life applications, we need many rows, in which each row contains a different number of columns (or, in other words, a different number of elements). Here, the best solution is to use jagged arrays (we perform memory allocation for each row on the basis of requirements).