Definizioni delle notazioni asintotiche più comuni

October 31st, 2009 by Matteo Valdina

Molto in breve le tre definizioni essenziali di notazione asintotica.

Theta di n, Θ(n) , limite asintoticamente stretto

Θ(g(n))= { f(n) : esistono delle costanti positive c1, c2 e n0 tali che 0 ≤ c1g(n) ≤ f(n) ≤ c2 g(n) per ogni n >= n0}

O grande di n, O(n), limite asintotico superiore

O(g(n))= { f(n) : esistono delle costanti positive c e n0 tali che 0 ≤ f(n) ≤ c g(n) per ogni n >= n0}

Omega di n, Ω(n), limite asintotico inferiore

Θ(g(n))= { f(n) : esistono delle costanti positive c e n0 tali che 0 ≤ cg(n) ≤ f(n) per ogni n >= n0}

post da android

August 29th, 2009 by Matteo Valdina

Primo post da un cellulare :-) però monta android :-)




thumbnail

Performance: CLI vs Win32 API

May 25th, 2009 by Matteo Valdina

In my little free time I develop some open source projects, for example my last creature is “Minimalistic Explorer“. This project is made in C# WPF for the UI and actually core is written in C#, but I hope to port the existing core in C++/CLI.

hd_me_735243

Read the rest of this entry »

Snippet: Icon from shell to ImageSource with alpha channel

May 21st, 2009 by Matteo Valdina

The following code snippet performs the following task:

  1. Get icon of the given file
  2. Convert in a bitmap preserving the alpha channel
  3. Convert it in a ImageSource

This code is shortcut to retrieve the displayed icon of a file. alternative way to do this is useing shell32.dll and SHGetFileInfo.

I have not used IconBitmapDecoder becuase this class lost the alpha channel.

   1:  public BitmapSource GetIconFromPath(string path)
   2:  {
   3:      System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(path);
   4:      System.Drawing.Bitmap bitmap = icon.ToBitmap();
   5:      return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(),
   6:              IntPtr.Zero, System.Windows.Int32Rect.Empty,
   7:              System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
   8:  }

Dettaglio di un HD Fireball 30 GB

April 19th, 2009 by Matteo Valdina

hd_fireball

Snippet: Enable Low Fragmentation Heap for all heaps

February 23rd, 2009 by Matteo Valdina

The following code is a code snippet that enable the Low Fragmentation Heap for all heaps. Remembers that a process has at last one heap but for example a CRT console application has practically at last two heaps. The first heap is default heap of process and the second is the CRT heap. If you use a lot of external DLLs is very common that one of this DLL allocate a private heap.

   1:  // code snippet that try to enable LFH for all heaps of your runnig program.
   2:      HANDLE* hHeaps = NULL;
   3:      int numHeap = GetProcessHeaps(0, NULL);
   4:      if(numHeap > 0)
   5:      {
   6:          ULONG ulEnableLFH = 2;
   7:          hHeaps = (HANDLE*)malloc(sizeof(HANDLE)*numHeap);
   8:          if(GetProcessHeaps(numHeap, hHeaps) == numHeap)
   9:          {
  10:              for(int i = 0; i < numHeap; i++)
  11:              {
  12:                  if(!HeapSetInformation(hHeaps[i], HeapCompatibilityInformation, &ulEnableLFH, sizeof(ulEnableLFH)))
  13:                  {
  14:                      printf("Failed to enable LFH for heap %d.", i);
  15:                  }
  16:              }
  17:          }
  18:          else
  19:          {
  20:              // quite strange !!!
  21:          }
  22:          free(hHeaps);
  23:      }

Suggested reading Windows Internals 4th edition for more details.

Analisi da riga di comando di un dump

February 11th, 2009 by Matteo Valdina

Nell’ultimo week-end, un applicazione in sviluppo è terminata inaspettatamente un infinità di volta. Generando un gran numero di memory dump, tutti di dimensioni considerevoli. La domanda sorge spontanea.
Come posso analizzare tutti questi dump senza sprecare un sacco del mio tempo?

Read the rest of this entry »

Windows Vista Recovery Disc

December 29th, 2008 by Matteo Valdina

Vi segnalo questo interessante post:

http://neosmart.net/blog/2008/windows-vista-recovery-disc-download/

Si tratta di un disco di 120 MB per poter eseguire il recovery di un installazione di Vista danneggiata. Purtroppo mi è capitato che si guastasse Vista (ma che strano :-) ) qualche file di configurazione ed il boot non era più praticabile, con questo CD ho potuto recuperare il mio sistema senza troppa fatica.

How to use NtQuerySystemInformation

December 27th, 2008 by Matteo Valdina

NtQuerySystemaInformation http://msdn.microsoft.com/en-us/library/ms724509(VS.85).aspx is useful undocumented and discouraged API of ntdll.dll. This API shouldn’t be used but in some case is a short way to get a lot information.

With this API you can make a lot of thinks but in this example is used to get some information about process.

This function should be linked at runtime, see more information at this link: http://msdn.microsoft.com/en-us/library/ms686944(VS.85).aspx.

To invoke NtQuerySystemInformation you should pass the follow argument:

  • Kind of information that you want get, in this example the SystemProcessInformation.
  • Address of a chunk of memory to place all information.
  • Size of previous chunk of memory.
  • A integer passed by reference that will filled with the size of return value.

Unfortunately size of second arguments isn’t know, a solution is pass a chunk of memory and if it is too small retry. This solution is possible because the NtQuerySystemInformation in case of a chunk of memory is too small it return a specific error code.

In this example enumerations and structures used by this program are placed in stdafx.h header file.

This example is written with Visual Studio 2008.

Download example

epiphany vuole mozilla-firefox?

October 5th, 2008 by Matteo Valdina

Read the rest of this entry »