Friday, June 17, 2011

Increase FD_SETSIZE

The maximum number of sockets which a Windows Sockets application can make use of is determined at compile time by the manifest constant FD_SETSIZE. This value is used in constructing the fd_set structures used in select(). The default value in winsock.h is 64. If an application is designed to be capable of working with more than 64 sockets, the implementor should define the manifest FD_SETSIZE in every source file before including winsock.h or winsock2.h. One way of doing this may be to include the definition within the compiler options in the makefile, for example adding -DFD_SETSIZE=128 as an option to the compiler command line for Microsoft C. It must be emphasized that defining FD_SETSIZE as a particular value has no effect on the actual number of sockets provided by a Windows Sockets implementation.

Wednesday, June 15, 2011

Hotkey to switch Japanese input mode

For MS IME:

To Hiragana: Shift + Caps Lock (switch between Hiragana and English)
To Katakana: Alt + Caps Lock

Thursday, June 9, 2011

ldr 12-bit displacement out of range

Somehow I get this error message while compiling my iPhone app.
The way to fix it is...
Go to Project info -> Build tab-> GCC 4.2 - Code Generation section, uncheck "Compile for Thumb".
That's it!

Wednesday, June 8, 2011

Create rounded corner view

1. #import <QuartzCore/QuartzCore.h>
2. Create a view, ex. named v
3. [v.layer setCornerRadius:8.0f] ;
4. [v.layer setMasksToBounds:YES] ;


Make sure you DO include QuartzCore/QuartzCore.h even compiler doesn't complain about it.

Debugging with Android native library

To figure out the function that your native library crashed within, use arm-eabi-addr2line which comes with the Android NDK.

How to use:
1. PATH_TO_ARM_EABI_ADDR2LINE/arm-eabi-addr2line -C -f -e libXXX.so
2. type in the address to look up (the address after pc in exception logs)

or in one command

PATH_TO_ARM_EABI_ADDR2LINE/arm-eabi-addr2line -C -f -e libXXX.so AddressToLookUp


Reference:
. http://www.codexperiments.com/android/2010/08/tips-tricks-debugging-android-ndk-stack-traces/

Memory alignment

Key points:
1. Each data element is stored at an address which is a multiple of its natural size.
2. Total size of the structure or union will be multiple of the natural size of the biggest data type in the structure or union.


To reduce the memory usage (Sets the alignment of all aggregate members to a specified byte boundary), use
. #pragma pack(1) before the declaration of the structure or union for Windows.
. __attribute__ ((packed)) after the } of the declaration for Linux.


Ex1. Windows.
#pragma pack(1)
struct alignment_test
{
    char x ;
    int y ;
    short z ;
} ;


Ex2. Linux

struct alignment_test
{
    char x ;
    int y ;
    short z ;
} __attribute__ ((packed)) ;

For details:
. http://kezeodsnx.pixnet.net/blog/post/27585076
. http://msdn.microsoft.com/en-us/library/aa505951.aspx
. http://www.ohse.de/uwe/articles/gcc-attributes.html#type-packed
. http://www.aleph1.co.uk/chapter-10-arm-structured-alignment-faq
. http://publib.boulder.ibm.com/infocenter/compbgpl/v9v111/index.jsp?topic=/com.ibm.xlcpp9.bg.doc/compiler_ref/pragma_pack.htm

Check clients which connect to Mac OS X Wi-Fi Internet Sharing

arp -i bridge100 -a bridge100 may be different on your Mac OSX