Monday, March 25, 2013

Writing high performance applications, specially that does batch processing is always fun. But most of the time you are unaware of whats going on under the hood.

You can use Performance Counter in Windows to find out how many threads your process has spawned, whats the current CPU and/or memory usage. But what if you want to know whats going on in your logic and with what frequency ?

For that you need to "Post" performance data out to windows operating system. So you could watch/log the data in order to generate nice and fancy reports for the superiors.

This post is all about sharing Performance Data Testing Tool that I built and would like to share. If you want to learn more about Windows Performance Counters, Check this Microsoft Article.

To learn the basics about how to code in .NET to post performance data to windows system, check this guy's Blog Post Part 1 and Part 2.

"Play with existing" part lets you change the values for current number of current counters that are being posted.

"Create/Delete" lets you create your own category and add counters to them. Once you've created new category with at least one counter, you can type the category name and counter name on the above section and click the Top Grab button then you can use Increment/Decrement button to up and down the values.

Monday, March 18, 2013

In this post I am going to share how we do whats called "constructors" in C++ or C# and for my C-only fellows, object initializers or <insert some term here>.

As I mentioned in my previous blog post that Objective-C has no such thing as constructors. We use the native non-instance method or what we call "static" method to allocate a new instance. That method is called alloc.

MyClass* myObj = [MyClass alloc]

The above code just creates an object in a fashion similar to having no constructors defined in our C++ or C# class.

If we want to implement the same logic in Objective-C, we are going to have to define something what most Obj-C developers call "initializers"

Initializers are nothing but methods that may take arguments and meant to be called right after allocation of a new object. So we could do the following in Objective-C. Lets do a "default constructor" in this post. I will make another post for parameter-ized constructor

@implementation Circle
- (id) init
{
self = [super init]; // calling base class's init in this case NSObject's init
if (self) { // checking to see if an object has been returned by NSObject's init
self.m_radius = 10; // set the default value to 10
}
return self; // In order for it to act like a constructor, it should return the object
}
@end

And this is how we create an object using the initializer defined above

Circle* circleObj = [[Circle alloc] init];

By the way, 'super' is a Java term for base class too. Somebody gets a title of 'copy-cat' here.

That's all folks for this post. Please let me know your comments in the comment box below if you have any.

Had embarrassing and frustrating moments when I had to screen a presentation off my Google Drive account and I saw the ridiculous error message with picture of a broken monkey with a wrench
"502, Thats an error The server encountered a temporary error and could not complete your request.. Please try again in 30 seconds, Thats all we know"

And their Apps Dashboard showing the following message, which scared my audience away from idea of using Google stuff for our business.

Basic Language Constructs

+ sign for static methods - sign for methods that require objects

Similarly for non-static methods just change the + sign to -. They are called Instance Methods.

-(void) SomeNonStaticMethod;

You may also have noticed that the return type is enclosed in () parenthesis which was weird to me.

No private methods

Thats right, no method is private. You can have member variables or attributes private by using @private but methods cannot be private.

Method calling

In C++ we have, when we have to call a method; we do

myObj.MethodName();

In Objective-C, its totally changed.

[myObj MethodName];

Tada! No Constructor

Yes, there is no such thing as constructor. All you do is call a native/built-in method alloc to create an object with default properties.

[MyClass alloc]; //Here is the object being created

But Objective-C developers have come up with something called initializers, so immediately after the object is created, an init method is called. Keep in mind that init is something developer has to create as a method that does some initialization work.

[ [MyClass alloc] init];

Weird asterisk * that reminds you of pointer will get on your nerve

Yes, that asterisk is for pointers. Every object reference is stored in pointers.

So in C++ we create objects by simply writing the following code

MyClass MyObj = MyClass();

In Objective-C, you will have to write the following code

MyClass *MyObj = [ [ MyClass alloc ] init];

Project files

Objective-C has similar to .h/.cpp structure for class declaration and definition but its most often called .h/.m or .h/.mm (for Objective-C++)

Keyword interface is not what you think

interface keyword in Objective-C is used for class declarations.

C++ code

class MyClass
{
public:
MyClass();
};

Objective-C will require you to write the following code for the above

Thats all folks! There is more information on the topic which I intend to write in future blog posts. If you are a C++ developer and thinking about taking a nosedive into Objective-C, above mentioned things should be enough for you to brace for.

I would love to hear your comments. They help me understand how useful my postings are.

Sunday, March 10, 2013

Hi,
Welcome to my very first (not really) blogging entry. I was monkeying around with an issue on internet and could not find any solution, however, I did find quite a few people looking for the same thing I was looking for. I tried something that worked, thought I would share that with the world.

So the issue is, You have the following Xml to bind to in your WPF application

But XmlDataProvider calls the .ToString() before passing it on to your converter. Which means, your converter won't get an XmlNodeList object, but just an empty string.

So lastly, I tried this which finally worked, Not an elegant way but it works. :)

The basic idea is to render all the items you want to count in an invisible (Visibility=Collapsed) ItemsControl and Bind a TextBlock to the Items.Count of that ItemsControl. Here is a little snippet to show the concept.