Archive

Posts Tagged ‘Debug’

How to mark a binary file as Debug/Release in C++

June 4th, 2011 1 comment

As all probably know, while developing a project, we compile it using Debug mode, whereas compiling for deployment purpose is performed in Release mode. Still, sometimes we need to combine Debug and Release binaries. For instance one might want to compile in Debug, but to use 3rd party’s binaries in Release. In this case, we’d like to have some simple way to distinguish binary files according to thier compiling type.

In some projects this goal is achieved by adding a character “d” in the end of Debug binary file. E.g. file named “Engine.dll” is called “Engined.dll” in Debug version. It works, but it is no plesant, because the project must have two different structures: one for Debug and another for Release.

Read more…

Categories: C++, General Tags: ,

How to extend Windows Phone 7 emulator’s functionality (unlock)

May 10th, 2011 2 comments

While programming to Windows Phone 7 (or another mobile device), very important instrument is the device’s emulator, integrated into development environment. Visual Studio 2010 supplies an emulator; while compiling & running our code (using either Silverlight or XNA technology), the emulator is running and creating an environment for our application. By the way, full Visual Studio 2010 is not must for development on WinPhone7; one can use a free environment “Microsoft Visual Studio 2010 Express” instead.

Read more…

Categories: Windows Phone 7 Tags: , ,

Getting OutOfMemory exception in .Net process, possible solutions.

May 7th, 2011 No comments

Getting OutOfMemoryexception in .Net process, possible solutions.

I want to share with you very interesting and complicated problem that we managed to overcome. I will describe all our resolution procedure step by step. Hope it will help others as it helped us, in any case I have learned a lot.

 

We have encountered a serious problem such as OutOfMemoryException

In my application – WinForm application i have managed code and un-managed (C/C++) 3’rd party code that perform many un-managed memory allocations at beginning of the process load and during runtime.

As we started to suffer from memory problems, we decided to enlarge address space that our process can use from 2 GB to 3 GB. This operation was done by using /LARGEADDRESSAWARE flag for our process and OS configured with /3GB. Unfortunately enlarge address space to our application seems to be good solution, but it didn’t help in our case.

So we started debugging and deeply investigate our Outofmemory problems. As usual main tool that we have used was WinDbg. Interesting things were discovered by using WinDbg and using following command “!address –summary” which shows us that we have not reached 3GB memory limit. Although that we have free memory, the memory wasn’t continuous so the CLR or native code failed to allocate memory. The problem appear to be defragmentation problem.

Read more…

Categories: .Net, C# Tags: , , , , ,

Working with System.Timers.Timer causing memory leaks

April 21st, 2011 2 comments

Short preamble,

Recently we had very serious problem with our application written in C#.NET; sometimes it has been completely stuck. This wasn’t easy reproducible scenario. As we started investigate the issue and debugging, more and more interesting things came up (not all code was written by our team, so debugging was not very easy thing). Memory almost wasn’t affected, but there was another symptom: thread count was growing and growing.

Finally the problem was discovered as following:
Read more…

Categories: .Net, C# Tags: , , ,

How to do mapping of NCLOB into string in NHibernate

April 11th, 2011 2 comments

I want to describe some error, which is accepted, while mapping NCLOB in NHibernate.

Working with Oracle database, we use “NVARCHAR2” type for strings. But this type has a constrain: it could contain no more then 2000 characters. If one needs to store some long text in Oracle, he will use an NCLOB type.

But, while mapping this type, next error is accepted:
ORA-01461: can bind a LONG value only for insert into a LONG column“.

How can we avoid this error? Two ways are possible:

1) Setting coulumn’s type to “AnsiString”:

        <property name="Contents" column="CONTENTS" type="AnsiString"/> 

Read more…

Categories: .Net, NHibernate Tags: , , , , ,

A problem with using static member in a class C#.NET

April 9th, 2011 3 comments

Today, I would like to tell about some bug I had in my C#.NET code, and a simple way to fix it.

When needed a transform matrix 3 x 3, I wrote a simple class Matrix3X3; this class includes static feilds “Zero” and “Ones” for Zero-Matrix and Ones-Matrix appropriately.
Let’s take a brief look of the implementation:

class Matrix3X3
{
        public static Matrix3X3 Zero = new Matrix3X3(0);
        public static Matrix3X3 Ones = new Matrix3X3(1);

        // class members ...

        public Matrix3X3(double value)
        {
                // Fill the whole matrix with same value.
                // ...
        }

        // class methods ...
}

Read more…

Categories: .Net Tags: , , ,

Using Debug.Assert while writing .Net code

March 3rd, 2011 No comments

Using Debug.Assert while writing .Net code

Today we have got new version of some product from other Team (component to retrieve data from DB). During our integration we have failed to run their code – got very strange errors ant etc.
Team which was responsible for this part of the project claimed that they checked everything and all functioning – but they did their tests only for Debug version of the Assemblies.

In .Net debug and release there shouldn’t be any difference in functionality Debug build version might be little bit slower. So we suspected in thread race problems and other weired stuff.

After several ours of debugging and phone calls with another team we have found the problem … it was really sad or funny to discover such simple mistake that developer can do.

See the following code:

public void DoSomething()
{

Debug.Assert(Foo());

}

public bool Foo()
{
//calculate something 
//set some data
}

command shown above is part of System.Diagnostics namespace useful for Debugging and making sure that code flow is working as designed by developer.
As you can see the problem in this code is that method called from Assertion. Very important not to call methods from Debuug.Assert this line of code will be removed by compiler during Release compilation.

The fixed code looks like this:
public void DoSomething()
{

bool res = Foo();

Debug.Assert(res);

}

public bool Foo()
{
//calculate something
//set some data

return sucsessFlag;

}
So the code flow doesn’t affected by the Assertion.
This looks small issue but believe me, very painful when it happening before version release :).

Categories: .Net Tags: ,