الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.
إكسير

إكسير مايكروسوفت دوت نت كود رقم 0004

بدأه Phoenix Programmer في 4 يوليو 2016 · 0 رد · 413 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1

What is the Miracle and the Disaster of the List object in Microsoft Dot Net Programming Code?

          By default arrays in any programming language cannot increase their size by default. Arrays are not linked lists; arrays are continuous memory allocated boxes that are free not reserved by the system.

C# Example:

          int[] numberAray = new int[10];

          As address number example, it will allocate memory boxes from starting memory address (4001) to ending memory address (4010). It is very risky to increase the array size and allocate the memory address (4011) since this location may be already reserved by the system or another application. So, it is a must to reallocate the array with the new size and copy old array data to the new bigger size array memory boxes.

C# List<T> Class: (Microsoft MSDN)

          List object is used to manage the automatic array size increase reallocation and automatic data copy from the old array to the new array then release the old array reservation in memory and return it back to the system to be used by another application or the system.

List Class Properties:

          Capacity: the size of the array used by the List object.

          Count: the number of elements added to the array used by the List object.

          In case the List capacity equals the List count, then List object will reallocate a new array with size = CAPACITY * 2 (Double Size the Old Array) then copy old array data to the new double sized array and release the oldarray to memory. This is a very costly performance operation when it operates too much in the code. So, the best practice is to forecast the List capacity during List object initialization in order to reduce the automaticarray management cost as much as possible.

C# List Disaster Example:

const int MAX_CAPACITY = 1,000,000;

List<int> numbersList = new List<int>();

for ( int i = 0; i < MAX_CAPACITY; i++){

          numbersList.Add(i);

}

 

C# List Miracle Example:

const int MAX_CAPACITY = 1,000,000;

// Starting List Capacity Initialize
List<int> numbersList = new List<int>( MAX_CAPACITY);

for ( int i = 0; i < MAX_CAPACITY; i++){

          numbersList.Add(i);

}

 

Dot Net Code Elixir Number 0004: 
https://goo.gl/CG7wbT

 

Draft 0004 Dot Net Code Elixir E-Book: 
https://goo.gl/HrygWP

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…