inline通常用於作為小而短的function的修飾字,用來提示compiler這段code很少,可以考慮直接在call它的地方作展開而不用真的作為function,作為function會有functions間跳轉之stack opeartions的overhead,直接在被call的地方展開就不用這些overhead,但會造成code體積變大,或許會造成cahce hit rate下降,所以交由compiler去安排
define的話就是直接展開了
2015年7月24日 星期五
Use tar and pigz to compress things in multithread
install pigz first
and then
tar -c --use-compress-program=pigz -f <tar.filename> <dir_to_zip>
2015年7月22日 星期三
make a big file
fallocate -l 10g filename
只有分配空間
dd if=/dev/zero of=fiename bs=1M count=10240
填零填到10GB後結束
只有分配空間
dd if=/dev/zero of=fiename bs=1M count=10240
填零填到10GB後結束
2015年6月14日 星期日
Compile QEMU in ubuntu 14.04
To compile QEMU in ubuntu 14.04, you need to download the needed libraries first
Btw, you can use -j8 to accelerate with 8 threads,' there is no space between 'j' and8', unlike compiling linux kernel.
sudo apt-get install zlib1g-dev libglib2.0-dev autoconf automake libtoolIf you need to browse the execution screen via a window in host instead of using VNC, you will need to install gtk.
sudo apt-get install build-essential libgtk2.0-dev libvte-devThen command ./configure --target-list="What you desire" --enable-gtk.
ex: ./configure --target-list="x86_64-softmmu" --enable-gtkThen command make, and it will make the files in some directory, ex:"x86_64-softmmmu".
Btw, you can use -j8 to accelerate with 8 threads,' there is no space between 'j' and8', unlike compiling linux kernel.
pthread
除了要#include <pthread.h>
編譯的時候還要下-pthread指令
pthread_create(pid,NULL,*void,(*void)arg);
第三項是pthread要跑的function位置,這個function只能接受一個argument傳入,限定為void type,有需求傳入多個arguments時,定一個struct把需要的arguments都包起來。可以回傳值,所以也限定為void*,因此function定義時要定成void* mydeffunc(void* arg)
ex:
void *doit(void *arg);
/*define a struct to wrap needed arguments*/
struct myDefStruct
{
struct sockaddr_in servaddr;
int sockfd;
};
/*call pthread_create的時候*/
/*when call pthread_create*/
struct myDefStruct *myDefPtr;
for ( ; ; ) {
clilen = sizeof(cliaddr);
connfd = accept(listenfd, (__SOCKADDR_ARG) &cliaddr, &clilen);
myDefPtr= (struct myDefStruct*)malloc(sizeof(struct myDefStruct));
myDefPtr->servaddr = cliaddr;
myDefPtr->sockfd = connfd;
pthread_create(&tid, NULL, &doit, (void*)myDefPtr);
}
/*如何取出void*型別的資訊*/
/*How to retrieve the data in void* type by casting*/
void *doit(void *arg)
{
int sockfd = ((struct myDefStruct*)arg)->sockfd;
struct sockaddr_in servaddr = ((struct myDefStruct*)arg)->servaddr;
...............
}
編譯的時候還要下-pthread指令
ex:gcc test.c -o test -pthread
pthread_create(pid,NULL,*void,(*void)arg);
第三項是pthread要跑的function位置,這個function只能接受一個argument傳入,限定為void type,有需求傳入多個arguments時,定一個struct把需要的arguments都包起來。可以回傳值,所以也限定為void*,因此function定義時要定成void* mydeffunc(void* arg)
ex:
void *doit(void *arg);
/*define a struct to wrap needed arguments*/
struct myDefStruct
{
struct sockaddr_in servaddr;
int sockfd;
};
/*call pthread_create的時候*/
/*when call pthread_create*/
struct myDefStruct *myDefPtr;
for ( ; ; ) {
clilen = sizeof(cliaddr);
connfd = accept(listenfd, (__SOCKADDR_ARG) &cliaddr, &clilen);
myDefPtr= (struct myDefStruct*)malloc(sizeof(struct myDefStruct));
myDefPtr->servaddr = cliaddr;
myDefPtr->sockfd = connfd;
pthread_create(&tid, NULL, &doit, (void*)myDefPtr);
}
/*如何取出void*型別的資訊*/
/*How to retrieve the data in void* type by casting*/
void *doit(void *arg)
{
int sockfd = ((struct myDefStruct*)arg)->sockfd;
struct sockaddr_in servaddr = ((struct myDefStruct*)arg)->servaddr;
...............
}
訂閱:
文章 (Atom)