Twitter Goodies

Dynamic Memory Allocation

To return the memory to the free store, you use the delete keyword. The delete operation frees up the memory allocated through new. Here’s how you’d free p_int:

delete p_int;

After deleting a pointer, it is a good idea to reset it to point to NULL again:

delete p_int;
p_int = NULL;

It isn’t necessary that you do this, but once a pointer is deleted, you can’t read or write to the memory it was pointing to because it’s been returned to the free store. By setting the pointer to NULL, if your code does try to dereference the pointer after it is freed, you will find out immediately because the program will crash. It happens a lot, even to experienced programmers

This is much better than finding out later, when your program crashes or corrupts some user’s data.

Luca A. Tarrini


Python: IndentationError: expected an indented block

Should be pretty explanatory. Probably caused by a mix of tabs and spaces. I converted all tabs to 4 spaces and now it’s working well.

Luca A. Tarrini


Rules for Static Constructors

A  static constructor is a special constructor that is an ideal place to initialize the values of static data when the value is not known at compile time (e.g., you need to read in the value from an external file, a database, generate a random number, or whatnot).

class SavingsAccount
{
    public double _currBalance;
    public static double _currInterestRate;

    static SavingsAccount()
    {
        _currInterestRate = 0.04;
    }
}
  • A given class may define only a single static constructor.
  • A static constructor does not take an access modifier and cannot take any parameters.
  • A static constructor executes exactly one time, regardless of how many objects of the type are created.
  • The runtime invokes the static constructor when it creates an instance of the class or before accessing the first static member invoked by the caller.
  • The static constructor executes before any instance-level constructors.

When a class has been defined as static, it is not creatable using the new keyword, and it can contain only members or data fields marked with the static keyword.

Reference: Pro C# 5.0 and the .NET 4.5 Framework.

Luca A. Tarrini


Namespaces in MainPage.xaml.cs

These namespaces fall into two general categories based on the first word in the name:

  • System.* .NET for new Windows 8 applications
  • Windows.* Windows Runtime (or WinRT)

ScreenHunter_122 May. 14 05.53

Namespaces that begin with Windows.UI.Xaml play a major role in the Windows Runtime.

Luca A. Tarrini


Test Driven Development

The concept behind TDD is to write a test before writing any production code, watch the code fail, write enough code to get the test to pass, then clean the code up or refactor if you can and repeat.

ScreenHunter_119 May. 09 11.53

Luca A. Tarrini


Pdf–Registered IFilter is not found

How to fix PDF search in Windows 8 64-bit?

ScreenHunter_119 May. 08 01.38

Checking Indexing options, Registered IFilter is not found and for some reason the 64-bit has a problem indexing PDF files. To fix the problem you need to download the missing iFilter here. Now you need to come back to Indexing Options and in Advanced Button hit Rebuild.

Luca A. Tarrini


Prefix++ or Postfix++

The preincrement operator (prefix ++) is used here.

for(pos = coll.begin(); pos != coll.end(); ++pos)

This is because it might have better performance than the postincrement operator. The latter involves a temporary object because it must return the old position of the iterator. For this reason, it generally is best to prefer ++pos over pos++.

Luca A. Tarrini


Set Up Wireless for Win Server 2008 R2 Hyper-V Virtual Machines

Windows 2008 R2 Hyper-V does not allow virtual machines to connect through a wireless network card. This video shows how to set up wireless Internet Connection Sharing (ICS) for virtual machines running inside Microsoft’s Hyper-V. Demonstrates how to create an internal virtual network and then connect the internal virtual network to a pair of virtual Ubuntu desktops. The internal virtual network is then bound to a wireless adapter using Internet Connection Sharing. Finally two Ubuntu desktops are shown using the wireless connection simultaneously with separate IP addresses and working browser.

Luca A. Tarrini


CreateQuery in Entity Framework 5.0

With previous version of Entity Framework a model created with the EF Designer would generate a context that derived from ObjectContext and entity classes that derived from EntityObject. In Visual Studio 2012 you get DbContext code generated by default for all new models created with the EF Designer. Existing models will continue to generate ObjectContext based code unless you decide to swap to the DbContext based code generator.

In EF 4.x,

var queryString = "SELECT VALUE c from SampleEntities.Contacts AS c WHERE c.FirstName = 'Robert'";
ObjectQuery<Contact> contacts = context.CreateQuery<Contact>(queryString);

To get around the issue get a reference to the ObjectContext and use that

var queryString = "SELECT VALUE c from SampleEntities.Contacts AS c WHERE c.FirstName = 'Robert'";                
ObjectQuery<Contact> contacts = 
    (((IObjectContextAdapter)context).ObjectContext.CreateQuery<Contact>(queryString));

Reverting Back to ObjectContext Code Generation, in the Properties window change the Code Generation Strategy from None to Default

ScreenHunter_107 Feb. 18 00.47

Luca A. Tarrini


Where can I find System.Web.MVC dll

Because of I read a post on where System.Web.MVC is located, then you can find it there: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll

Luca A. Tarrini