• الإعلانات

    • فيصل الحربي

      تسجيل عضوية جديدة في المنتدى   01/31/2016

      السلام عليكم ورحمة الله وبركاته  عزيزي العضو الجديد :  حاليا رسالة الإيميل لتأكيد صحة إيميلكم تذهب للبريد العشوائي ( جاري حل المشكلة )  فإذا لم تجد رسالة التحقق من إيميلكم في صندوق الوارد لديكم إتجه للبريد العشوائي ( JUNK)  وقم بتفعيل إشتراككم من هناك   

البحث في المنتدى

Showing results for tags 'إكسير'.

  • البحث بالتاقات

    اكتب الكلمات المفتاحيه بينها علامه الفاصله
  • البحث بكاتب الموضوع

تم إيجاد 5 نتيجة

  1. What is the Miracle and the Disaster of the Dictionary object in Microsoft Dot Net Programming Code?           Arrays direct indexing is one of the fastest retrieval operations of cost Big O(1). This is very useful in case you know the location of the item in the array. But in case you do not know the location, then you have to search the whole array from start to end till you find the object/value you want which has a cost of Big O(n) where n is the array size.           Using numbers to index a value/object in an array has its complexity where retrieving value by name is much easier than by number. C# String Indexing vs Number Indexing Example: // Array with number indexing List<int> employeeAgeList = new List<int>(); employeeAgeList.add(33); int khaledAge = employeeAgeList[0]; // Age: 33 // Array with Text indexing using Hashing algorithms to transform // Text to array index number in the background Dictionary<string, int> employeeAgeDictionary = new Dictionary<string, int>(); employeeAgeDictionary.add(“Khaled”, 33); int khaledAge = employeeAgeDictionary [“Khaled”]; // Age: 33 Hashing algorithm which transforms objects to an index number in the array:           Dictionary is using arrays in the background. But with a mathematical function, it takes a hashing code and retrieves array index number. Each object has hash code method called GetHashCode() which produces a 32-Bit integer value for each object. But the hashing algorithm does not guarantee the uniqueness of the hash code. Secondly, the mathematical transformationalgorithm from hash value to array index number does not guarantee the uniqueness of the array index value which is called a collision in the mathematical transformation function.           Dictionary uses a method to handle collisions by using a list in each box in the array where a collision occurs. In case of collision, a sequential search will be added to search inside the list that handles the collision box to return the correct value from collision list. C# Dictionary Explained By Example: string keyName1 = “Khaled”; int khaledAge = 5; Dictionary<string, int> namesAgeList = new Dictionary<string, int>(); namesAgeList.add(keyName1, khaledAge); What Happens in the above code? Dictionary Strategy is doubling the size of the array to lower possible collisions (possible keys result in the same array index number). Mathematical Algorithm to output the array index number: hashsize: Array Size keyName1: “Khaled” Array Index number: H(keyName1) H(keyName1) = [GetHash(keyName1) + 1 + (((GetHash(keyName1) >> 5) + 1) % (hashsize – 1))] % hashsize Algorithm Explained By Microsoft MSDN:      Here, GetHash(key) is, by default, the result returned by key’s call toGetHashCode() (although when using the Hashtable, you can specify a custom GetHash() function). GetHash(key) >> 5 computes the hash for keyand then shifts the result 5 bits to the right – this has the effect of dividing the hash result by 32. The % operator performs modular arithmetic. hashsizeis the number of total slots in the hash table. (Recall that x % y returns the remainder of x / y, and that this result is always between 0 and y – 1.) Due to these mod operations, the end result is that H(key) will be a value between 0 and hashsize – 1. Since hashsize is the total number of slots in the hash table, the resulting hash will always point to within the acceptable range of values. Collision Resolution in the Dictionary Class By Microsoft MSDN:      The Dictionary class differs from the Hashtable class in more ways than one. In addition to being strongly-typed, the Dictionary also employs a different collision resolution strategy than the Hashtable class, using a technique referred to as chaining. Recall that with probing, in the event of acollision, another slot in the list of buckets is tried. (With rehashing, thehash is recomputed, and that new slot is tried.) With chaining, however, a secondary data structure is utilized to hold any collisions. Specifically, each slot in the Dictionary has an array of elements that map to that bucket. In the event of a collision, the colliding element is prepended to the bucket’s list.      To better understand how chaining works, it helps to visualize theDictionary as a hashtable whose buckets each contain a linked list of items that hash to that particular bucket. Figure illustrates how series of items thathash to the same bucket will form a chain on that bucket.      The Dictionary in the above figure has eight buckets, drawn in yellow and running from the top down. A number of Employee objects have been added to the Dictionary. When an Employee object is added to the Dictionary, it is added to the bucket that its key hashes to and, if there’s already an Employee instance there, it’s prepended to the list of Employees. That is, employees Al and John hash to the same bucket, as do Fred, Zak, and Amy, and Sam and Ted. Rather than reprobing in the event of a collision, as is done with theHashtable class, the Dictionary simply chains any collisions onto the bucket’s list. Disadvantages of Dictionary: Rehashing is an expensive process. Rehashing is the increase of thehashtable size to minimize collisions as much as possible). Solution: Initialize Dictionary  const int CAPACITY_SIZE = 100; Dictionary<string, int> nameAgeList = new Dictionary<string, int>( CAPACITY_SIZE); Dictionary eats memory (Dictionary uses large memory size). As more the items added to the dictionary, it leads to double, triple or more the arraysize with respect to the number of items in the array to lower the possiblecollisions resulted from the hashing algorithm. Solution: Do not use Dictionary for a big number of items unless high speed is required and you have enough memory.   Dot Net Code Elixir Number 0005:  https://goo.gl/ouZCJo Draft 0005 Dot Net Code Elixir E-Book:  https://goo.gl/HrygWP      
  2. 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
  3. What is the importance of the Using Statement in Microsoft Dot Net Programming Code?      One of the most important things in managed languages is the automatic management of the application objects in memory using Runtime Environment named Garbage Collector (GC) which is responsible for releasing unused objects from memory and returning their locations in memory to system. But the more the GC runs, the more the application becomes slower since the process is not smooth and fast especially where unmanaged code is used which is a hard slow process done by the GC since GCdoes not have enough information about codes and objects from outside its environment.      Microsoft adds IDisposable interface with an implementation pattern to be used by developers for any unmanaged code to allow unmanaged codememory release by calling the Dispose method from the IDisposable interface without relying on the GC to do the process which leads to very smaller memory and much higher performance during application life cycle by lowering the GC need to release unmanaged code and the number of times it needs to run. C# IDisposable Design Pattern: using System;   class BaseClass : IDisposable {    // Flag: Has Dispose already been called?    bool disposed = false;      // Public implementation of Dispose pattern callable by consumers.    public void Dispose()    {       Dispose(true);       GC.SuppressFinalize(this);              }      // Protected implementation of Dispose pattern.    protected virtual void Dispose(bool disposing)    {       if (disposed)          return;         if (disposing) {          // Free any other managed objects here.          //       }         // Free any unmanaged objects here.       //       disposed = true;    }      ~BaseClass()    {       Dispose(false);    } }   Using Statement, Microsoft Definition:      Provides a convenient syntax that ensures the correct use of IDisposableobjects.      As a rule, when you use an IDisposable object, you should declare and instantiate it in a using statement. The using statement calls the Dispose method on the object in the correct way; it also causes the object itself to go out of scope as soon as Dispose is called. Within the using block, the object is read-only and cannot be modified or reassigned.      The using statement ensures that Dispose is called even if an exception occurs while you are calling methods on the object. You can achieve the same result by putting the object inside a try block and then calling Dispose in a finally block; in fact, this is how the using statement is translated by the compiler. C# Using Statement Example: using (Font font1 = new Font("Arial", 10.0f)) {     byte charset = font1.GdiCharSet; }   Examples of IDisposable objects:      SqlConnection, DataSet, DataTable, SqlDataReader, Font, DataView, SqlCommand, SqlDataAdapter … etc.   Dot Net Code Elixir Number 0003:  https://goo.gl/KuOsjO Draft 0003 Dot Net Code Elixir E-Book:  https://goo.gl/HrygWP
  4. What is the difference between Managed Code and UnManaged Code in Microsoft Dot Net Programming Code? Managed Code:            Is written to target the services of the managed runtime execution environment (like Common Language Runtime in .NET Framework). Themanaged code is always executed by a managed runtime execution environment rather than the operating system directly. Managed refers to a method of exchanging information between the program and the runtime environment. Because the execution of code is governed by the runtime environment, the environment can guarantee what the code is going to do and provide the necessary security checks before executing any piece of code. Because of the same reason the managed code also gets different services from the runtime environment like Garbage Collection, type checking, exception handling, and bounds checking … etc. This way managed code does not have to worry about memory allocations, and type safety … etc. Applications written in Java, C#, and VB.NET … etc. target a runtime environment which manages the execution and the code written using these types of languages. These languages are known as Managed Code. Managed code is always compiled into an Intermediate Language (MSIL in case of .NET Framework). The compiler used by .NET framework to compile managed codecompiles it into Intermediate Language and generates the necessarymetadata, which is symbolic information that describes all of the entry points and the constructs exposed in the Intermediate Language (e.g., methods, properties) and their characteristics. The Common Language Infrastructure(CLI) Standard describes how the information is to be encoded, and programming languages that target the runtime emit the correct encoding.           In .NET Framework Managed Code runs within the .Net Framework’s CLR and benefits from the services provided by the CLR. When we compile the managed code, the code gets compiled to an intermediate language (MSIL) and an executable file is created. When a user runs the executable file, the Just In Time Compiler of CLR compiles the intermediate language into a native code specific to the underlying architecture. Since this translation happens by the managed execution environment (CLR), the managedexecution environment can make guarantees about what the code is going to do, because it can actually reason about it. It can insert traps and sort of protection around the code. If it’s running in a sandboxed environment, it can insert all the appropriate garbage collection hooks, exception handling, type safety, array bounce, index checking and so forth.           Managed code also provides platform independence. As the managed code is first compiled to intermediate language, the CLR’s JIT Compiler takes care of compiling this intermediate language into the architecture specific instructions. UnManaged Code:            Is directly executed by the Operating System. Typically, applications written in VB 6, C++, and C … etc. are all examples of unmanaged code.Unmanaged code typically targets the processor architecture and is always dependent on the computer architecture. UnManaged code is always compiled to target a specific architecture and will only run on the intended platform. This means that if you want to run the same code on different architecture, then you will have to recompile the code using that particular architecture. UnManaged code is always compiled to the native code which is architecture specific. When we compile unmanaged code, it gets compiled into a binary x86 image. This image always depends on the platform on which the code was compiled and cannot be executed on the other platforms that are different than the one on which the code was compiled. Unmanaged codedoes not get any services from the managed execution environment.           In unmanaged code, the memory allocation, type safety, and security … etc. need to be taken care of by the developer. This makes unmanaged codeprone to memory leaks like buffer overruns and pointer overrides and so forth.           UnManaged executable files are basically a binary image, x86 code, loaded into memory. The program counter gets put there and that’s the last the Operating System knows. There are protections in place around memory management and port I/O and so forth, but the system doesn’t actually know what the application is doing. What Dot Net FrameWork programming languages can use UnMaaged Code?           UnManaged code can be written with C++, and C# … etc. Dot Net FrameWork programming languages. Why UnManaged Code is needed? Legacy – native code long predates managed code, and there are still native apps to maintain. Performance – all things being equal, native code should be faster and have a smaller memory footprint than managed code (things are rarely equal though, and for I/O bound tasks, the difference is negligible); also, non-deterministic garbage collection can play hell with real-time code. System or hardware-specific hacks – native code may have access to system calls or libraries that the managed code may not (such as for parallel processing or vector processing, although I imagine most managed languages should be able to expose an API for such operations). No Virtual Machine (Dot Net FrameWork RunTime Environment) available – you may be targeting a system for which no Virtual Machine has been developed, or doesn’t have the resources to run managed code (such as a microcontroller or other embedded system); also, your target system may not need the capabilities of a full-up Virtual Machine (predominately CPU-bound tasks, limited I/O … etc.). Maximum speed of execution – The managed code layer adds around 10% overhead to the program. Maximum flexibility – Some features of some APIs are unavailable through the managed code library. Using unmanaged APIs from a managed code program is possible but more difficult, and introduces its own performance issues. Dot Net Code Elixir Number 0002: https://goo.gl/gDi0kw Draft 0002 Dot Net Code Elixir E-Book: https://goo.gl/HrygWP
  5. What is the difference between using Empty String (“”) vs (string.Empty) in Microsoft Dot Net Programming Code? Answer using C# Dot Net Programming Language: Code 1: string textValue = “”; Code 2: string textValue = string.Empty; Code 1: each time empty string quotes are found, they are translated to a new empty string object. So, each “” is a new allocated useless object in memory especially for string since string object is an Immutable object (Any action with the object will lead to new allocated object and not modify the used object). Code 2: each time string.Empty is used, all empty string variables are assigned to only one static string object which reduces memory used for empty strings by assigning all empty strings to only one global empty string object which has special MSIL code in Dot Net to handle all empty strings as only one global string object during Active Dot Net framework life time. Note: there are tests on the internet shows a very small difference in speed (Milliseconds) which means nothing in most applications, but the main point here is reducing memory mainly and reducing number of useless objects the Garbage Collector need to release from memory. Dot Net Code Elixir Number 0001: https://goo.gl/9ZDBez Draft 0001 Dot Net Code Elixir E-Book: https://goo.gl/HrygWP