2015/03 10

C program memory layout

C program의 일반적 memory layout objdumphttp://www.thegeekstuff.com/2012/09/objdump-examples/ c++ layout 분석 (hello.cc)#include class hello { public: int a; hello(); ~hello(); void show();}; hello::hello() {}hello::~hello() {}void hello::show() { printf("%d\n", a);} int main(){ hello *h = new hello(); return 0;} g++ -c hello.cc 컴파일 하면 hello.o 라는 object 파일이 생성된다. . nm 을 이용하여 symbol table 을 찾을 수 있다. . ..

카테고리 없음 2015.03.23

struct

python 에서는 binary packing 을 위해서 struct 라는 모듈을 제공한다. 문자 바이트 순서 크기와 정렬 @ 시스템에 따름 = 시스템에 따름 없음 Big endian 없음 ! 네트워크 (Big endian) 없음 FormatC TypePython typeStandard sizeNotesxpad byteno value ccharstring of length 11 bsigned charinteger1(3)Bunsigned charinteger1(3)?_Boolbool1(1)hshortinteger2(3)Hunsigned shortinteger2(3)iintinteger4(3)Iunsigned intinteger4(3)llonginteger4(3)Lunsigned longinteger4(3)..

Passion/Python 2015.03.23

pthread_join vs. pthread_mutex_lock

일반적으로 thread 를 생성하면 main 은 pthread_join 을 통해서 child thread가 끝날 때까지 기다려야 한다. 하지만 main 에서 pthread_join 대신에 자신을 deadlock 시키는 것이 pthread_join 을 사용하는 것보다 성능상의 이득을 볼 수 있다고 한다. #include #include #include pthread_mutex_t g_NONSTOP; void *t_func(void *data){ int id; id = *((int *)data); while(1) { //printf("(%lu) [%d]\n",pthread_self(), id); }} int main(){ pthread_t tid; int a = 1; int thr_id; thr_id = p..

카테고리 없음 2015.03.20

[design pattern] Singleton

Singleton 은 Object Oriented programming 에서 instance 의 개수를 globally 1개를 가지고 싶을 때 사용하는 design pattern 이다. 예를 들어 global configuration 을 관리하는 class를 만들어서 환경 변수등을 저장할 때 실수로 여러개의 instance를 생성하면 문제가 될 수 있으므로 코딩 시 원천적으로 instance를 한개를 생성하는 방법을 제공하여야 한다. 주요 방법론ㅇ 생성자를 호출할 수 없게 만든다. (즉 생성자를 private 으로 선언한다) 참조: http://www.bogotobogo.com/DesignPatterns/singleton.php

카테고리 없음 2015.03.13

boost installation in ubuntu

Installation boost library in Ubuntu Download source Installationapt-get install libboost-all-devThe installed libraries are located in /usr/include/boost Example기본적으로 include 파일은 #include 또는 #include "boost/xxxx.hpp" 로 사용하면 된다.주의: boost directory 는 기존 c++ 컴파일러가 자동으로 include 하는 디렉토리가 아니기 때문에 -I 옵션에 boost directory 를 명시해 주어야 한다./** * To compile: * g++ -o test test.cpp -I/usr/include -lboost_threa..

카테고리 없음 2015.03.08