Monday, December 21, 2009

Motorola will release Android based smartphone, ST800 in 2010

Recently, Motorola introduced new Android based smartphone, ST800.

It supports GSM & CDMA networks and uses two SIM cards so that two phone numbers can be used on a device.

Main features: 3G/WiFi/WAPI, 3.7" FWVGA Display, 854X480 resolution, Bluetooth 2.1, LED Flash 500M pixel camera, GPS, 3.5mm earphone jack

Sunday, September 27, 2009

Wednesday, August 19, 2009

Job Search Tips: How to Address Job Hopping on a Resume

Job Search Tips: How to Address Job Hopping on a Resume

Finding iPhone Application's memory leaks

I found these useful guides by Googling.

1. Finding iPhone Memory Leaks: A “Leaks” Tool Tutorial: This explains with an iPhone device, but I am also sure we can use this tool, "Instruments" with an iPhone simulator. We can do it by choosing "iPhone Simulator" instead of "iPhone" and your own application by "Attach to process" drop down menu.

2. Memory Usage Performance Guide by Apple

Sunday, July 12, 2009

Starting with Objective-C for iPhone Apps

Recently, I need to start iPhone App programming in the project I am working.

Here are some useful references for beginners.

1) Dave Mark and Jeff LaMarche, "Beginning iPhong Development", Apress, 2009.
2) Erica Sadun, "The iPhone Developer's Cookbook", Addison-Wesley, 2008.
3) "Learn Objective-C on the Mac", 2009.

1) Bert Altenberg, Alex Clarke and Philippe Mougin, "Becom an Xcoder", 2008.
2) "Learn Objective-C 2.0 Language"

1) Apple's iPhone Dev Center
2) Stanford University, CS 193P "iPhone Application Programming"
3) CocoaLab
4) Jeff LaMarche's iPhone Programming Blog

Tuesday, April 21, 2009

Highlighting CUDA syntax in VS2005

How to enable syntax highlighting for CUDA files in VS2005

GPU programming using CUDA: Study #1

Study material source
CUDA U [Education] Exercise

Methods : See CUDA Reference Manual for details.

1. Allocate host memory and device memory
cudaMalloc(void **devPtr, size_t count): allocate memory on the GPU
cudaMallocHost(void **hostPtr, size_t size): allocate page-locked memory on the host

2. Copy memory host to device, device to device, and device to host
cudaMemcpy(void *dst, const void *src, size_t count, enum cudaMemcpyKind kind): copies data between GPU and host
cudaMemcpyKind: cudaMemcpyHostToDevice, cudaMemcpyDeviceToDevice, cudaMemcpyDeviceToHost

3. Free host and device memory
cudaFree(void *devPtr): frees memory on the GPU

4. Block until all threads in the block have written their data to shared memory
__syncthreads(); // called on the GPU

5. Block until the device has completed
cudaThreadSynchronize(); // called on the host

Kernel configuration and Launch
dim3 dimGrid(1024);
dim3 dimBlock(256);
kernel_name <<< dimGrid, dimBlock>>>(kernel_arguments);

1D Indexing
single block:
int idx = threadIdx.x;
int reversed_idx = blockDim.x - 1 - threadIdx.x;

multi blocks:
int offset = blockIdx.x * blockDim.x;
int idx = offset + threadIdx.x;
int reversed_offset = blockDim.x * (gridDim.x - 1 - blockIdx.x);
int reversed_threadIdx = blockDim.x - 1 - threadIdx.x;
int reversed_idx = reversed_offset + reversed_threadIdx;

Using shared memory
extern __shared__ int s_data[];

1. Host: CPU
2. Device: GPU
3. Kernel: a function that runs on the GPU, executed by an array of threads
4. Grid: a set of blocks (dimension of grid == # blocks a grid)
5. Block: a set of threads (dimension of block == # threads in a block)
6. Thread: one thread runs kernel
7. Shared memory:

Declarations on functions
__host__: host only
__global__: interface
__device__: device only
__shared__: shared memory

GPU programming using CUDA

Starting GPU programming using CUDA

[University Courses]

Monday, March 30, 2009

Useful tool for the presentation of your mobile application

"Real-Time Remote Control" and "Presentation Tools" will be very useful.

Pocket Controller Pro

Wednesday, March 11, 2009

Random Number Generator in C++

Random Number Generator in C++

See here

Sunday, March 1, 2009

How to run windows mobile application as a background process?

To send your application to the background, you can use Hide() function.

For example, when you have a form (myForm) to hide, call this, myForm.Hide(). This results in that myForm.visible is set with "false".

To check that your application is really running on background, let's go to the "Settings -> System tab -> Memory -> Running programs tab".

Unfortunately, you cannot find your application on the list. (But, actually your application is running as a backroung process.)

Now, let's check with "Remote Process Viewer". Click "Microsoft Visual Studio 2005 -> Visual Studio Remote Tools -> Remote Process Viewer". (You need to connect your mobile device to your computer.)

You can surely find your application's name on the Process list. To kill it, click "X" icon on toolbar menu.

This is a drawback when you use Hide() function to send your application to the background.

Here is another way to overcome this problem.

It is to use the Native function "ShowWindow()" with the ‘Minimized’ property:

static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_MINIMIZE = 6;
public void Hide()
ShowWindow(myForm.Handle, SW_MINIMIZE);


How to capture screenshots of mobile device or emulator

Here is a procedure to follow to take a screenshot.

1. Open "Microsoft Visual Studio 2005 -> Visual Studio Remote Tools -> Remote Zoom In".

2. Select one on a "Select a Windows CE Device" dialog, which is the thing you want to connect. Make sure a device connected to your computer.

3. You will see the screenshot. If you want to take another screenshot, click "Target -> Refresh" on the menu of the Remote Zoom In, or press F5 key.

4. Now, you can save the screenshot as an image (BMP). Select "File -> Save As".

Friday, February 27, 2009

Reset StreamReader in C#


This is a little bit weired, but it works.

During reading a file, I wanted to reset file pointer to start from the begining of a file. I used FileStream and StreamReader in C#.

My initial ideal was to call these two functions;

FileStream fs;
StreamReader sr;
fs.Seek(0, SeekOrigin.Begin);
sr.BaseStream.Seek(0, SeekOrigin.Begin);

However, this didn't work although I checked fs.Position == 0 and sr.BaseStream.Position == 0.

Finally, I solved this problem as follows;

FileStream fs;
StreamReader sr;
fs.Seek(0, SeekOrigin.Begin);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
sr.BaseStream.Position = 0;

Frankly, I can't understand why I need to use these three lines for resetting StreamReader. But, anyway it works well, and I can start to read from the begining of a file.

Tuesday, February 24, 2009

IEEE 754 floating point format

IEEE single precision format

Toggle bulbs and switches

room lighting.. room with 100 bulbs and switches..

100 people goes in one by one.

1st person toggles all switches.

2nd person toggles all switeches which are multiles of 2 (2,4,6..)

and so on ( till 100th person toggling only 100th switch)

once finished with all, ==> which all bulbs are ON.

1th: all switches are ON
2nd: 2, 4, 6, 8, ... switches are OFF
3rd: 3, 9,... OFF
3rd: 6 12 ... ON
100th: only toggle 100th switch

sizeof operator

In the programming languages C and C++, the unary operator 'sizeof' is used to calculate the sizes of datatypes. sizeof can be applied to all datatypes, be they primitive types such as the integer and floating-point types defined in the language, pointers to memory addresses, or the compound datatypes (unions, structs, or C++ classes) defined by the programmer. sizeof is a compile-time operator that returns the size in bytes of the variable or parenthesized type-specifier that it precedes. -- --

Here is an interesting test for the size of several types by myself.

#include "stdio.h"

#define mySizeOf(x) ((char*)(&(x)+1)-(char*)(&x))

struct myType { // This is a structure containing four variables of different types
char a;
int b;
float c;
double d;

struct blankType { // This is a structure with no variable

class CBlankClass { // This is a class with no member variable
CBlankClass() {};
~CBlankClass() {};

void function1() {};
void function2() {};

class CMyClass { // This is a class with a int type member variable
int memberVar1;

CMyClass() {};
~CMyClass() {};

void function1() {};
void function2() {};

void main()
char var1;
printf("Size of char type = %d\n", mySizeOf(var1));

int var2;
printf("Size of int type = %d\n", mySizeOf(var2));

float var3;
printf("Size of float type = %d\n", mySizeOf(var3));

double var4;
printf("Size of double type = %d\n", mySizeOf(var4));

char var5[] = "AB";
printf("Size of char array ""AB"" = %d\n", mySizeOf(var5));

struct myType var6;
printf("Size of struct myType = %d\n", mySizeOf(var6));

struct blankType var7;
printf("Size of struct blankType = %d\n", mySizeOf(var7));

CBlankClass var8;
printf("Size of class CBlankClass = %d\n", mySizeOf(var8));

CMyClass var9;
printf("Size of class CMyClass = %d\n", mySizeOf(var9));

Size of char type = 1
Size of int type = 4
Size of float type = 4
Size of double type = 8
Size of char array AB = 3
Size of struct myType = 24
Size of struct blankType = 1
Size of class CBlankClass = 1
Size of class CMyClass = 4

From this result, interesting things are these,
Size of struct myType = 24
--> For a struct myType, if it has only "char a", its size is 1. But, if it has "char a" and "int b", its size becomes not 5 but 8. If it has "char a", "int b", and "float c", its size becomes 12.
Size of struct blankType = 1
Size of class CBlankClass = 1
--> Both black structure and class (no member variable) have its size 1.
--> For class, member functions don't affect on the size.
Size of class CMyClass = 4
--> If a class has member variables, its size will be the same to the situation of structre above.

memcpy() vs. memmove() in C

Here is the difference between memcpy() and memmove().

str = "strings are good";
memmove(str + 8, str + 11, 4);
This returns --> strings are are good
memcpy(str + 8, str + 11, 4);
This returns --> strings are ared


/* memcpy example */

int main ()
char str1[]="Sample string";
char str2[40];
char str3[40];
memcpy (str2,str1,strlen(str1)+1);
memcpy (str3,"copy successful",16);
printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
return 0;

str1: Sample string
str2: Sample string
str3: copy successful


/* memmove example */

int main ()
char str[] = "memmove can be very useful......";
memmove (str+20,str+15,11);
puts (str);
return 0;

memmove can be very very useful.

Thursday, February 12, 2009

How to connect a server from mobile client in C#

I need to know this.

Get "unique device ID" of a mobile device

I searched Internet a lot to find how to get "unique device id" for mobile devices, which is not dependent on any application data.

I am developing on Windows Mobile 6 with HTC phone.

There are severay ways to do it.

1) Use GetDeviceUniqueID(): GetDeviceUniqueID() requires at least 8 bytes of data to generate a hash. Furthermore, you should not expect GetDeviceUniqueID() to return the UUID string as HAL_GET_DEVICEID does. It will return application-specific hash that is unique for this particular device. You should treat it as a sequence of bytes.

2) Use HAL_GET_DEVICEID: This does not work on Smartphone unless your code is signed with a privleged certificate.

3) Get IMEI(International Mobile Equipment Identity) number: The IMEI number is a unique 15-digit code used to identify an individual GSM mobile phone in a GSM network. The IMEI number can be displayed on most phones by dialing the code *#06#. Every phone has a unique IMEI number, which is usually printed under the battery on the phone. The IMEI number is used in many mobile applications since the unique number makes it possible to lock software to a particular phone. This effectively prevents unauthorized copying of an application.
--> Use Tapi dll
--> Make your code (See, References (2))
: References
1) Getting the IMEI number: a UIQ 3 code example

2) IMEI in C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

// Reference:
public class clsDeviceInfo
private string _manufacture;
private string _model;
private string _revision;
private string _serialNumber; // IMEI
private string _subscriberID; // IMSI

public string Manufacture
get { return _manufacture; }

public string Model
get { return _model; }

public string Revision
get { return _revision; }

public string SerialNumber
get { return _serialNumber; }

public string SubscriberID
get { return _subscriberID; }

public clsDeviceInfo()

private void GetDeviceInfo()
IntPtr hLine;
int dwNumDev;
int num1 = 0x20000;

lineInitializeParams.dwTotalSize = (uint)Marshal.SizeOf(lineInitializeParams);
lineInitializeParams.dwNeededSize = lineInitializeParams.dwTotalSize;
lineInitializeParams.dwUsedSize = lineInitializeParams.dwUsedSize;
lineInitializeParams.dwOptions = 2;
lineInitializeParams.hEvent = IntPtr.Zero;
lineInitializeParams.hCompletionPort = IntPtr.Zero;

// lineInitializeEx
int result = NativeTapi.lineInitializeEx(out hLine, IntPtr.Zero, IntPtr.Zero, null, out dwNumDev, ref num1, ref lineInitializeParams);
if (result != 0)

// lineNegotiateAPIVerison
int version;
int dwAPIVersionLow = 0x10004;
int dwAPIVersionHigh = 0x20000;
result = NativeTapi.lineNegotiateAPIVersion(hLine, 0, dwAPIVersionLow, dwAPIVersionHigh, out version, out lineExtensionID);
if (result != 0)

// lineOpen
IntPtr hLine2 = IntPtr.Zero;
result = NativeTapi.lineOpen(hLine, 0, out hLine2, version, 0, IntPtr.Zero, 0x00000002, 0x00000004, IntPtr.Zero);
if (result != 0)

// lineGetGeneralInfo
int structSize = Marshal.SizeOf(new LINEGENERALINFO());
byte[] bytes = new byte[structSize];
byte[] tmpBytes = BitConverter.GetBytes(structSize);

for (int index = 0; index < tmpBytes.Length; index++)
bytes[index] = tmpBytes[index];

// make initial query to retrieve necessary size
result = NativeTapi.lineGetGeneralInfo(hLine2, bytes);

// get the needed size
int neededSize = BitConverter.ToInt32(bytes, 4);

// resize the array
bytes = new byte[neededSize];

// write out the new allocated size to the byte stream
tmpBytes = BitConverter.GetBytes(neededSize);
for (int index = 0; index < tmpBytes.Length; index++)
bytes[index] = tmpBytes[index];

// fetch the information with properly size buffer
result = NativeTapi.lineGetGeneralInfo(hLine2, bytes);
if (result != 0)

int size;
int offset;

size = BitConverter.ToInt32(bytes, 12);
offset = BitConverter.ToInt32(bytes, 16);

// manufacture
if (size > 0 && offset > 0)
_manufacture = Encoding.Unicode.GetString(bytes, offset, size);
_manufacture = _manufacture.Substring(0, _manufacture.IndexOf('\0'));

size = BitConverter.ToInt32(bytes, 20);
offset = BitConverter.ToInt32(bytes, 24);

// model
if (size > 0 && offset > 0)
_model = Encoding.Unicode.GetString(bytes, offset, size);
_model = _model.Substring(0, _model.IndexOf('\0'));

size = BitConverter.ToInt32(bytes, 28);
offset = BitConverter.ToInt32(bytes, 32);

// revision
if (size > 0 && offset > 0)
_revision = Encoding.Unicode.GetString(bytes, offset, size);
_revision = _revision.Substring(0, _revision.IndexOf('\0'));

size = BitConverter.ToInt32(bytes, 36);
offset = BitConverter.ToInt32(bytes, 40);

// serial number (IMEI)
if (size > 0 && offset > 0)
_serialNumber = Encoding.Unicode.GetString(bytes, offset, size);
_serialNumber = _serialNumber.Substring(0, _serialNumber.IndexOf('\0'));

size = BitConverter.ToInt32(bytes, 44);
offset = BitConverter.ToInt32(bytes, 48);

// subscriber id (IMSI)
if (size > 0 && offset > 0)
_subscriberID = Encoding.Unicode.GetString(bytes, offset, size);
_subscriberID = _subscriberID.Substring(0, _subscriberID.IndexOf('\0'));

// lineClose for hLine2

// lineShutdown for hLine

private struct LINEEXTENSIONID
public IntPtr dwExtensionID0;
public IntPtr dwExtensionID1;
public IntPtr dwExtensionID2;
public IntPtr dwExtensionID3;

public uint dwTotalSize;
public uint dwNeededSize;
public uint dwUsedSize;
public uint dwOptions;
public System.IntPtr hEvent;
public System.IntPtr hCompletionPort;
public uint dwCompletionKey;

private struct LINEGENERALINFO
public int dwTotalSize;
public int dwNeededSize;
public int dwUsedSize;
public int dwManufacturerSize;
public int dwManufacturerOffset;
public int dwModelSize;
public int dwModelOffset;
public int dwRevisionSize;
public int dwRevisionOffset;
public int dwSerialNumberSize;
public int dwSerialNumberOffset;
public int dwSubscriberNumberSize;
public int dwSubscriberNumberOffset;

private class NativeTapi
public static extern int lineClose(IntPtr hLine);

public static extern int lineGetGeneralInfo(IntPtr hLine, byte[] bytes);

public static extern int lineGetAddressCaps(IntPtr hLineApp, int dwDeviceID, int dwAddressID, int dwAPIVersion, int dwExtVersion, byte[] lpAddressCaps);

public static extern int lineInitializeEx(out IntPtr lpm_hLineApp, IntPtr hInstance, IntPtr lpfnCallback, string lpszFriendlyAppName, out int lpdwNumDevs, ref int lpdwAPIVersion, ref LINEINITIALIZEEXPARAMS lpLineInitializeExParams);

public static extern int lineNegotiateAPIVersion(IntPtr m_hLineApp, int dwDeviceID, int dwAPILowVersion, int dwAPIHighVersion, out int lpdwAPIVersion, out LINEEXTENSIONID lpExtensionID);

public static extern int lineOpen(IntPtr m_hLineApp, int dwDeviceID, out IntPtr lphLine, int dwAPIVersion, int dwExtVersion, IntPtr dwCallbackInstance, int dwPrivileges, int dwMediaModes, IntPtr lpCallParams);

public static extern int lineShutdown(IntPtr m_hLineApp);

Add remider function in Windows Mobile application

I need to do this.

Wednesday, February 11, 2009

Sorting 2D string list in C#

* In application code
// Declare a variable for data
public static List recordList = new List();

// Set a list
// For example,
// 2/11/2009, apple, 20
// 2/10/2009, banana, 5
// 1/30/2009, pineapple, 3
recodeList.Add(new clsDataRecord(DateTimeVar1, TextVar1, IntVar1));
recodeList.Add(new clsDataRecord(DateTimeVar2, TextVar2, IntVar2));
recodeList.Add(new clsDataRecord(DateTimeVar3, TextVar3, IntVar3));

// Call sorting by date
clsDataRecord.CompType = clsDataRecord.ComparisonType.Date;
// Sorted result will be
// 1/30/2009, pineapple, 3
// 2/10/2009, banana, 5
// 2/11/2009, apple, 20

// Call sorting by text
clsDataRecord.CompType = clsDataRecord.ComparisonType.Text;
// Sorted result will be
// 2/11/2009, apple, 20
// 2/10/2009, banana, 5
// 1/30/2009, pineapple, 3

// Call sorting by number
clsDataRecord.CompType = clsDataRecord.ComparisonType.Number;
// Sorted result will be
// 1/30/2009, pineapple, 3
// 2/10/2009, banana, 5
// 2/11/2009, apple, 20

* Class for clsDataRecord
using System;
using System.Collections;

class clsDataRecord : IComparable
public enum ComparisonType
Date = 1,
Text = 2,
Number = 3

// This class has three different members.
// You can customize these with your own data.
private DateTime _date;
private string _text;
private int _number;

private static ComparisonType _compType;

public clsDataRecord(DateTime date, string text, int number)
_date = date;
_text = text;
_number = number;

public DateTime Date
get { return _date; }
set { _date = value; }

public string Text
get { return _text; }
set { _text = value; }

public int Number
get { return _number; }
set { _number = value; }

public static ComparisonType CompType
get { return _compType; }
set { _compType = value; }

public override string ToString()
return String.Format("{0} - {1} - {2}", _date.ToShortDateString(), _text, _number.ToString());

public int CompareTo(object obj)
if (obj is clsDataRecord)
clsDataRecord r2 = (clsDataRecord)obj;

switch (_compType)
case ComparisonType.Date:
return _date.CompareTo(r2.Date);
case ComparisonType.Text:
return _text.CompareTo(r2.Text);
case ComparisonType.Number:
return _number.CompareTo(r2.Number);
throw new ArgumentException("Object is not an clsDataRecord.");

Rectangular Array vs. Jagged Array in C#

Friday, February 6, 2009

Set DateTimePicker in C# with specific date

string example = "2/6/09";
char[] delimiter = {'/'};
string[] dateInfo = example.Split(delimiter);

private System.Windows.Forms.DateTimePicker myDateTimePicker;

myDateTimePicker.Value = new DateTime(int.Parse(dateInfo[2]) + 2000, int.Parse(dateInfo[0]), int.Parse(dateInfo[1]));

string to integer in C#


string str = "09";
int year = int.Parse(str) + 2000;

year == 2009

Split string in C#

Example code

class TestStringSplit
static void Main()
char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
string text = "one\ttwo three:four,five six seven";
System.Console.WriteLine("Original text: '{0}'", text);
string[] words = text.Split(delimiterChars);
System.Console.WriteLine("{0} words in text:", words.Length);
foreach (string s in words)


Original text: 'one two three:four,five six seven'
7 words in text:


Related work searching

"" provides an interesting related work searching facility supoorted by a large number of professonal societies - led by IEEE.

How to access the file system on Windows Mobile 5 Smartphone emulator

Here is the short description about how to access the file system on Windows Mobile emulator.

If your application is using data files or images, you need to copy them in a memory for the emulator.

I assume that you use Visual Studio 2005, you didn't connect any mobile device to your desktop, and you have already installed ActiveSync.

Here is simple procedure.
1. Under "Tools" in Visual Studio 2005, select "Device Emulator Manager".
2. Scroll down the list of emulated devices until you see what you want to use.
(i.e., I selected "Windows Mobile 5.0 Smartphone Emulator".)
3. Under "Actions" in the emulator manager, select "Connect". Then, an emulator will pop up.
4. Under "Actions" in the emulator manager, select "Cradle".
5. Now open ActiveSync. Under "File" in ActiveSync, select "Connection Settings". Check "Allow connections to one of the following" and select "DMA". You only need to do this once. When you click “Connect” in ActiveSync, it connects to the emulator and give you some setup screens. After the first time, the connection happens automatically when you “cradle” the emulator via the Device Emulator manager.
6. Now you can browse the file system on the emulator by selecting “Explore” on ActiveSync (or
selecting “Mobile Device” from My Computer). By default, your application is deployed to
“Program Files\[your application name]”.