2012年12月27日 星期四

Android - Memory leak note

1. Used the StringBuilder to avoid the memory leak:

Error :
for (int i=1; i<65535 i="i" p="p">{
    String aaa = aaa + "test sting"; // this will have memory leak
    String aaa = null;
}

Solution :

for (int i=1; i<65535 i="i" p="p">{

    StringBuilder sb;
    sb.append("test sting");
    String aaa = sb.ToString();
    sb.setLength(0);
}

2. Recycle the message

a.removeMessages(0);
Message msg = a.obtainMessage();
a.sendMessage(msg);

2012年12月25日 星期二

Liunx - How to fix "/bin/sh : pushd : not found"

How to fix the "/bin/sh : pushd : not found" ?
Modify your sh file ...

#!/bin/sh

to

#!/bin/bash

2012年10月15日 星期一

Linux - How to open device of type of input ?

0. Include file
#include

1. Get device name :
int GetDevices()
{
int fd = -1;
char name[80];

fd = open("/dev/input/event1", O_RDONLY); // open "dev/input/event1" and read only

if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1)
{
    name[0] = '\0';
    DBGMSG("ioctl fail, path = %s \n",devname);
    close(fd);
    return fd;
}
DBGMSG("ioctl OK, name = %s \n",name);

close(fd);
return fd;
}

2. Read data from devices

int fd = -1;
fd = GetDevices();
if (fd <0 devices="devices" err="%d\n" errno="errno" fail="fail" nbsp="nbsp" open="open" p="p">
struct input_event ev;
ret = read(fd, &ev, sizeof(struct input_event));

if (ret < 0)
{
DBGMSG("read data from devices fail, err = %d\n",errno);
}
else
{
DBGMSG("ev.type = %d\n",ev.type);
DBGMSG("ev.code = %d\n",ev.code);
DBGMSG("ev.value = %d\n",ev.value);
}

close(fd);
return fd;
}


2012年9月5日 星期三

Android - build error : undefined reference to `__isoc99_sscanf'

Build error :

undefined reference to `__isoc99_sscanf'
Solution :

#define _GNU_SOURCE

ubuntu - How to boot ubuntu 12.04 on EUFI system ?

1. Format the USB disk to fat32.
mkfs.vfat /dev/sdb1
2. Used the live CD and entry the OS.
3. Following the cmd ..

sudo -s
mkdir /mnt/ubuntu && mount /dev/sda5 /mnt/ubuntu
mount --bind /dev /mnt/ubuntu/dev
mount -t sysfs /sys /mnt/ubuntu/sys
mount -t proc /proc /mnt/ubuntu proc
chroot /mnt/ubuntu bash

4. Install the "grub-efi-amd64-bin"
apt-get install grub-efi-amd64-bin grub-efi-amd64
5. Execute the grub 
grub-install

6. Make the grub config file
cd /etc/grub.d
cp 40_custom 06_custom

and edit this file ...

menuentry "Windows 7 (loader) (on /dev/sda1)" --class windows --class os {
insmod part_gpt
insmod fat
set root='(hd0,gpt1)'
search --no-floppy --fs-uuid --set=root 46bd-600e
chainloader ($root)/EFI/Boot/bootx64.efi
}

7. Execute the grub ...
update-grub2

8. Create the folder on USB disk
mkdir -p efi/boot

9. copy the grub file to USB disk
cp /boot/grub/grub.efi /efi/boot/bootx64.efi

2012年8月13日 星期一

Android - build error and solution

Error 1 :

host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp

frameworks/base/libs/utils/RefBase.cpp: In member function ‘void android::RefBase::weakref_type::trackMe(bool, bool)’:

frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing ‘const android::RefBase::weakref_impl’ as ‘this’ argument of ‘void android::RefBase::weakref_impl::trackMe(bool, bool)’ discards qualifiers [-fpermissive]make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] 错误 1

Solution :

$ gedit frameworks/base/libs/utils/Android.mk
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)

Modify to ...

LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive

Reference link : http://goo.gl/gb2XC

Error 2 :
host Prebuilt: monkeyrunner (out/host/linux-x86/obj/EXECUTABLES/monkeyrunner_intermediates/monkeyrunner) host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp <命令行>:0:0: 错误: “_FORTIFY_SOURCE”重定义 [-Werror] :0:0: 附注: 这是先前定义的位置 cc1plus:所有的警告都被当作是错误

Solution :

build/core/combo/HOST_linux-x86.mk line 61: 

find this line ...

-HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0

modify to ...

+HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

Reference link : http://goo.gl/kUEpI

2012年5月28日 星期一

CE : Error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.UnsafeValueTypeAttribute..ctor'

Error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.UnsafeValueTypeAttribute..ctor'

Solution:
Update your project to .NET 3.5 in your VS2008.

2012年5月25日 星期五

C/C++ : 位元判斷與改變

其實只是做個筆記,懶的背起來,免的每次要用又要想一下。

判斷某一個 flag 有沒有被 enable : &
enable 某一個 flag : |
disable 某一個 flag : ~&

example :


unsigned int g_dwFlags;
void Enable(unsigned int dwFlags)  {  g_dwFlags |= dwFlags;  }
void Disable(unsigned int dwFlags) {  g_dwFlags &= (~dwFlags);  }

資料來源 : http://www.csie.nctu.edu.tw/~skyang/bitwiseshift.zhtw.htm


2012年5月24日 星期四

VC/C++ : LINK : fatal error LNK1000: Internal error during IncrBuildImage

VC/C++ compiler 出現錯誤 : LINK : fatal error LNK1000: Internal error during IncrBuildImage

Solution : 
專案 -> 屬性 -> Debug -> 啟用累加連結 -> 否(/INCREMENTAL:NO)


資料來源 : http://www.cnblogs.com/happytogether/archive/2010/04/22/1718182.html

2012年5月23日 星期三

VC/C++ : fatal error C1010

VC/C++ compiler 出現錯誤訊息 :  fatal error C1010: 尋找先行編譯標頭檔指示詞時碰到未預期的檔案結尾。您的原始檔中是否忘了加上 '#include "stdafx.h"'?

Solution:
專案 -> 屬性 -> 組態 -> 所有組態
組態屬性 -> C/C++ -> 先行編譯標頭檔 -> 建立/使用先行編譯標頭檔 -> 未使用先行編譯標頭檔

VC/C++ : HRESULT:0x800736B1

一般只會出現在以 Debug 模式下的時候會出現的錯誤。

Solution :

專案 -> 屬性 -> C/C++ -> 執行階段程式庫 -> 多執行緒偵錯(/MTd)


2012年5月21日 星期一

C# - Reboot source code


using System.Management;
       
...      
        public static void PowerOff()
        {

            ManagementClass mc_os = new ManagementClass("Win32_OperatingSystem");
            mc_os.Scope.Options.EnablePrivileges = true;

            foreach (ManagementObject mo in mc_os.GetInstances())
            {
                mo.InvokeMethod("Shutdown", null, null);
            }

            mc_os.Dispose();
        }
...

PS. 必須加入參考 : 專案->加入參考->Systme.Management

資料來源 : http://www.dotblogs.com.tw/nobel12/archive/2009/10/05/10912.aspx

2012年3月27日 星期二

Ubuntu - amule setting

1.install amule into ubuntu
>sudo apt-get install amule-daemon

2.edit your amule file
>sudo vim /etc/default/amule

AMULED_USER="your name"
AMULED_HOME="home patch"

3.start your amule
>sudo /etc/init.d/amule-daemon start

4.create
echo -n YourPassword | md5sum

5.stop your amule
>sudo /etc/init.d/amule-daemon stop

6.edit your amule file
>sudo vim /home/amule/.aMule/amule.conf

[ExternalConnect]
AcceptExternalConnections=1
ECAddress=
ECPort=4712
ECPassword=YourPassword
[WebServer]
Enabled=1
Password=YourPassword
PasswordLow=
Port=4711
UseGzip=1
UseLowRightsUser=0
PageRefreshTime=120
Template=

7.restart your amule
>sudo /etc/init.d/amule-daemon start

8.You can use your amule web on "http://localhsol:4711/"

reference : http://blog.c2sr.com/?p=12

Ubuntu - eth0 static ip

sudo vim /etc/network/interfaces

auto eth0
iface eth0 inet static
address 10.0.0.100
netmask 255.255.255.0
gateway 10.0.0.1

sudo /etc/init.d/networking restart