Author Archive

“Understanding” neural networks

“Understanding” neural networks

A very basic, yet intuitive, introduction on neural networks. The examples are well-described, highly informative and inspiring.

“Understanding” neural networks

“Understanding” neural networks

Một bài viết thú vị ở mức a bờ cờ về neural networks. Các ví dụ rất trực quan và dễ hiểu. 

Về Memory leak trong MFC/C++ trên Windows

<Bài này viết lâu rồi, trên Live Spaces, nay move qua đây>

Những ai lập trình C có kinh nghiệm chắc hẳn đều thừa nhận rằng việc C/C++ giao hẳn trách nhiệm quản lí bộ nhớ cho người lập trình thực sự là một ưu điểm mạnh mẽ, và cũng chính là khuyết điểm lớn của ngôn ngữ này. Với tư tưởng đó, lập trình viên C++ luôn phải làm một công việc khó chịu và mất nhiều thời gian là phát hiện và loại trừ memory leak trong chương trình. Entry này không trình bày cặn kẽ và chi tiết về memory leak, mà chỉ là ghi lại một số kinh nghiệm của người viết. Hi vọng bài viết sẽ có ích với những người (và chỉ những người) đã có kinh nghiệm làm việc với C++, đã có những hiểu biết cơ bản về memory leak như: tại sao lại có memory leak, tại sao phải tránh memory leak v.v…
Read more…

Differences between Control.Invalidate(), Control.Refresh and Control.Update


Before discussing each one of the above functions, let’s look at how winforms controls paint.

Windows controls paint is response to WM_PAINT messages. This message is sent when UpdateWindow or RedrawWindow is called, or by the DispatchMessage function when the application gets a WM_PAINT through the message queue. On getting the WM_PAINT message, the control paints its background and then the foreground if necessary. Double-buffering and transparency is honored while painting and then the OnPaint event is fired to give the user a chance to perform his custom painting.

With this background, let’s look at the above mentioned three functions in more detail,

Control.Invalidate( ) / Control.Invalidate(bool) / Control.Invalidate(Rectangle) / Control.Invalidate(Rectangle, bool) / Control.Invalidate(Region) / Control.Invalidate(Region, bool)

The bool parameter denotes whether the user wants to invalidate the child controls of the control on which he is calling Invalidate. The Rectangle parameter are the bounds to invalidate and the region parameter is the region to invalidate. All the overloads essentially end up calling one of the RedrawWindow, InvaliateRect or InvalidateRgn functions. If RedrawWindow is called then this may result in a WM_PAINT message being posted to the application message queue (to invalidate the child controls).

The important thing to note here is that these functions only “invalidate” or “dirty” the client area by adding it to the current update region of the window of the control. This invalidated region, along with all other areas in the update region, is marked for painting when the next WM_PAINT message is received. As a result you may not see your control refreshing (and showing the invalidation) immediately (or synchronously).


Update function calls the UpdateWindow function which updates the client area of the control by sending WM_PAINT message to the window (of the control) if the window’s update region is not empty. This function sends a WM_PAINT directly to WNDPROC() bypassing the application message queue.

Thus, if the window update region is previously “invalidated” then calling “update” would immediately “update” (and cause repaint) the invalidation.


By now, you might have guessed what Refresh( ) would be doing. Yes, it calls Invalidate(true) to invalidate the control and its children and then calls Update( ) to force paint the control so that the invalidation is synchronous.

Windows Touch in C++ fashion

A great article and presentation on how to multitouch in C++. It’s really worth watching and trying…


I am currently having some fancy ideas about various topics that I can dive in. The bad news is I have too little time for them right now, so although I intended to start very soon, but I’m not sure when I can really dig into these messes.

These ideas are very straightforward:

1. Security in Cloud computing, data mining/querying on encrypted databases and practical facts.

This idea came to me in the RIVF conference last month. The general consideration is how can we trust the Cloud service provider (i.e. Windows Azure, Amazon Web Service…) that they will not steal our data, how much our data is secured? When we performing queries, how can we know if the provider is faithful enough?

One of possible solutions is encrypting the data before sending it to the provider. The problem hence raise, since how could we do data mining, query “our” encrypted data which are stored on provider’s infrastructure?

This is really a hard (and interesting!) problem, and it draws many attentions from academic scholars. It is pretty useful to apply the academic idea on commercial service like Windows Azure or AWS…

2. The second idea comes from my experiences on GPU computing with CUDA.

DirectCompute has been announced in PDC 2009, and it seems promising in cross-platform GPU computing. Nonetheless, the documentation of DirectCompute seems to be lacking (even on MSDN DirectX). I want to dig into DirectCompute, perform some benchmarks to check it performance, and then comparing with CUDA or OpenCL. I believe this will point out some interesting conclusions.

So if one of the readers of this blog would like to investigate to these problems, please contact me. I’m not sure this will lead to anywhere, but at least it can help you improving some skills 😉

Undefined behavior in C and C++

19/08/2010 3 comments

Another great article diving into the mess of standard C/C++ and describing the basic concepts which are often ignored by programmers.

Nonetheless, I have just read part 1. Have no time for this right now. Place it here as a bookmark, read later…