Configurar VS 2010 para poder debuguear en .NET Framework codigo fuente.

Hace tiempo Microsoft anuncio la liberacion del codigo fuente del .Net Framework ademas de habilitar el soporte a la depuracion a traves de Visual Studio. A continuacion tratare de enlistar los pasos a realizar para poder configurar dicho soporte en Visual Studio 2010.

Pasos a realizar:

1. Como paso inicial es necesario descargar e instalar Visual Studio 2010 QFE. El cual al ser instalado habilitara las opciones necesarias.

2. Una vez instalado el parche, dentro de Visual Studio 2010, en el Menu Tools -> Options… -> Debugging -> General, deseleccionar la opcion “Enable Just My Code(Managed only)” y seleccionar la opcion “Enable source server support”.



3. Por ultimo, es necesario especificar la localicacion de los fuentes, en la opcion Symbols, dentro de Debuggin se selecciona el Servidor, en caso de que no aparezca algun servidor se puede agregar http://referencesource.microsoft.com/symbols, ademas es necesario especificar la ruta para el cache la cual podria ser “C:\Users\electrocucaracha\Symbols”.

 

Implementacion de suma de cadenas parte II

Como mejora de la implementacion anterior y estudio de C#, sobretodo en las mejoras incoorporadas en la version 4, me decidi a implementar una nueva version de esta suma. Basicamente los cambios agregados fue la suma por bloques y la suma de ceros, que pienso yo que reduce la cantidad de operaciones, por lo menos unas 19 veces ya que es el bloque de numeros que toma.

Habria que hacer un profundo analisis en revisar la cantidad de codigo usado si este mejora el performance del algoritmo.

StringInteger.cs

...
        public static readonly int MAX_ULONG_LENGTH = ulong.MaxValue.ToString().Length;
...
        public static StringInteger operator +(StringInteger lhs, StringInteger rhs)
        {
            //Validaciones
 
            String tmpX = lhs.Container, tmpY = rhs.Container;
            ulong x, y, result = 0;
            int limit = lhs.Container.Length > rhs.Container.Length ? lhs.Container.Length : rhs.Container.Length;
            StringBuilder tmp = new StringBuilder(limit);
            do
            {
                if (IsTheOnlyOperand(ref tmpX, ref tmpY, (int)result))
                {
                    result = 0;
                    tmp.Insert(0, tmpX + tmpY);
                }
                else
                {
                    x = RetrieveNextNumber(ref tmpX);
                    y = RetrieveNextNumber(ref tmpY);
 
                    result += x + y;
                    if (result.ToString().Length == MAX_ULONG_LENGTH)
                    {
                        tmp.Insert(0, result.ToString().Substring(1));
                        result = 1;
                    }
                    else
                    {
                        tmp.Insert(0, result);
                        result = 0;
                    }
                }
            } while (!(string.IsNullOrEmpty(tmpX) && string.IsNullOrEmpty(tmpY)));
            tmp.Insert(0, result);
 
            return new StringInteger(tmp.ToString());
        }//operator+
 
        private static bool IsTheOnlyOperand(ref string firstOperand, ref string secondOperand, int carry)
        {
            bool response = false;
            firstOperand = SanitizeStringInput(firstOperand);
            secondOperand = SanitizeStringInput(secondOperand);
 
            if (string.IsNullOrEmpty(firstOperand) && !string.IsNullOrEmpty(secondOperand))
            {
 
                secondOperand = secondOperand.Substring(0, secondOperand.Length - 1) +
                    Convert.ToChar(Convert.ToInt32(secondOperand[secondOperand.Length - 1]) + carry);
                response = true;
            }
            else if (string.IsNullOrEmpty(secondOperand) && !string.IsNullOrEmpty(firstOperand))
            {
                firstOperand = firstOperand.Substring(0, firstOperand.Length - 1) +
                    Convert.ToChar(Convert.ToInt32(firstOperand[firstOperand.Length - 1]) + carry);
                response = true;
            }
 
            return response;
        }//IsTheOnlyOperand
 
        private static string SanitizeStringInput(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
 
            input = input.TrimStart('0').Trim();
            if ("".Equals(input))
            {
                input = "0";
            }
 
            Regex pattern = new Regex(@"^\d+$");
            if (!pattern.IsMatch(input))
            {
                throw new ArgumentException("The string value " + input + " is not a integer value");
            }
 
            return input;
        }//SanitizeStringInput
 
        private static ulong RetrieveNextNumber(ref string stringNumber)
        {
            int length = stringNumber.Length > MAX_ULONG_LENGTH - 1 ? MAX_ULONG_LENGTH - 1 : stringNumber.Length;
            int index = stringNumber.Length - length;
            ulong number = length > 0 ? ulong.Parse(stringNumber.Substring(index, length)) : 0;
            stringNumber = stringNumber.Remove(index, length);
 
            return number;
        }//RetrieveNextNumber

 

Implementacion de suma de cadenas

Continuando con la serie de operaciones con numeros grandes, desarrollo la implementacion de una suma de valores contenidos en una cadena, la cual nos puede evitar el desboramiento de bufer. Realizando un ligero analisis encontramos que seguimos limitados por el manejo de indices de arreglos, ya que solo nos permite indexarlos con numeros enteros.

Suma.java

...
	private static String sumar(String a, String b) {
		//Validaciones
...
		int x, y, result = 0;
		int limite = a.length() > b.length() ? a.length() : b.length();
		char[] tmp = new char[limite + 1];
		for (int i = 1; i <= limite; i++){
			x = i <= a.length() ? a.charAt(a.length() - i) - '0' : 0;
			y = i <= b.length() ? b.charAt(b.length() - i) - '0' : 0;
			result += x + y;
			tmp[tmp.length - i] = (char) ((result % 10) + '0');
			result /= 10;
		}
 
		if ( result > 0){
			tmp[0] = (char) ((result % 10) + '0');
			return String.valueOf(tmp);
		}
		return String.valueOf(tmp, 1, tmp.length -1);
	}

 
 
 
Tags

Resources
 
FireStats icon Powered by FireStats