출처 : http://sweeper.egloos.com/3059940

1. shared_ptr
shared_ptr의 내용은 다음 링크를 참고하기 바라며, 특히 3-9 Circular reference 챕터를 자세히 읽어보기 바란다.
(위 링크엔 shared_ptr의 circular reference에 대한 예제가 포함되어 있다)
2. weak_ptr
shared_ptr은 자신이 참조하고 있는 객체(메모리 주소)에 대해 reference counting을 함으로써, 객체의 수명에 직접적으로 관여한다.
shared_ptr 객체 하나가 소멸되더라도, 동일한 메모리 주소를 참조하고 있는 다른 shared_ptr 객체가 있으면 참조하고 있던 메모리 주소의 객체는 소멸되지 않는다.
하지만, weak_ptr은 shared_ptr을 관리하기 위한 reference count에 포함되지 않는다.
즉, shared_ptr의 객체만 참조할 뿐, shared_ptr의 reference count를 올리지 않는 것이다.
사실 weak_ptr이 shared_ptr을 참조할 때 shared_ptr의 weak reference count는 증가
Read More
출처 : http://egloos.zum.com/sweeper/v/2826435
 
1. auto_ptr
TR1이 발표되기 전까지 std::auto_ptr이 C++ Standara library의 유일한 스마트 포인터였다.
스마트 포인터의 기본적인 특성인 자신이 소멸될 때 가리키고 있는 대상에 대해 자동으로 delete 해줘 메모리 누수 걱정은 없게 작성이 되어 있다.
하지만, auto_ptr은 유일 소유권 개념이 있어서, 객체가 복사되는 순간(복사생성 또는 대입연산) 원래의 auto_ptr은 바로 NULL 처리가 되어 버린다.
class AAA;
 
// RAII 방식으로... AAA 객체 생성
std::auto_ptr<AAA> AAAObject(new AAA());
 
// 복사가 되는 순간, AAAObject는 NULL이 되고, 이제 BBBObject 만이 객체를 가리킨다.
std::auto_ptr<AAA> BBBObject(AAAObject);
 
// 역시 대입이 되는 순간, BBB는 NULL, 이제 AAA가 객체를 가리킴.
AAAObject = BBBObject;
이렇듯 괴상망측한 복사 동작으로
Read More

출처 : http://shaeod.tistory.com/396

boost란 C++ 커뮤니티 및 C++ 개발자들이 개발하고 있는 오픈 소스 라이브러리의 집합으로써,

C++를 위한 멀티스레딩, 정규표현식, 의사 난수 발생, 선형대수 등을 지원하는 유용한 라이브러리 집합이다.

또한 C++ 표준에 영향을 미치기도 하며, 최신 표준인 C++11에 boost 라이브러리가 몇 가지 표준으로 채택되기도 하였다.

boost는 UNIX 및 Windows 등을 포함하여 거의 모든 최신 운영체제에서 작동하며 상업 및 비상업적으로 모두 사용이 가능하다.

boost다운로드는 http://www.boost.org/ 서 하며, 14. 06. 20일 기준 최신 버전은 1.55.0 버전이다.

1.48 버전도 같은 방법으로 빌드가 가능한 걸로 보아, 앞으로 최신버전이 나와도 비슷한 방법으로 빌드할 수 있을 거 같다.

boost를 다운 받았으면 적당한 곳에 압축을 푼다.

필자의 경우

Read More

구조체 선언에서의 문제!!

리눅스는 이렇게 선언한다.

typedef struct
{
    char a;
    int b;
} __attribute__((packed)) myST;

AIX에서는

#pragma options align=packed
#pragma options align=reset

HP에서는

#pragma pack 1
#pragma pack 8

COMPAQ 에서는

#pragma pack 1
#pragma pack 0

Sun 에서는

#pragma pack(1)
#pragma pack()

Read More

* 16진수 유니코드 문자 “%uD55C%uAC00%uC778” 같은 문자열을 한글로 변환하는 방법

  – 자바스크립트
document.write(unescape('%ud55c%uae00'));
  – 자바에서 unescape() 사용하기
  – 닷넷
    1. Microsoft.JScript 어셈블리를 참조한다.
    2. escape    => Microsoft.JScript.GlobalObject.escape(“바꿀 문자열”);
         unescape => Microsoft.JScript.GlobalObject.unescape(“바꿀 문자열”);
 
    ※ 닷넷에서 ‘\uD55C’ 형태인 경우에는 ‘\’ 문자를 ‘%’로 변경하고 작업을 해 주어야 한다.
 
Read More
void TestFunc()
{
MYGetActivePwrScheme pFunc1 = NULL;
MYGetCurrentPowerPolicies pFunc2 = NULL;
MYSetActivePwrScheme pFunc3 = NULL;

HINSTANCE hInstance = NULL;

hInstance = LoadLibrary( "powrprof" );
if( hInstance )
{
pFunc1 = (MYGetActivePwrScheme)GetProcAddress( hInstance, "GetActivePwrScheme" );
if( pFunc1 == NULL )
{
TRACE("GetActivePwrScheme Fail");
ERROR_ROUTINE( hInstance );
}

pFunc2 = (MYGetCurrentPowerPolicies)GetProcAddress( hInstance, "GetCurrentPowerPolicies" );
if( pFunc2 == NULL )
{
TRACE("GetCurrentPowerPolicies Fail");
ERROR_ROUTINE( hInstance );
}

pFunc3 = (MYSetActivePwrScheme)GetProcAddress( hInstance, "SetActivePwrScheme" );
if( pFunc3 == NULL )
{
TRACE("SetActivePwrScheme Fail");
ERROR_ROUTINE( hInstance );
}

UINT uiActivePwrSchIndex;
GLOBAL_POWER_POLICY stGlobalPwrPly;
POWER_POLICY stPwrPly;

if( ((pFunc1)( &uiActivePwrSchIndex )) == 0 )
{
TRACE("Call GetActivePwrScheme Error");
ERROR_ROUTINE( 
Read More
int CSearchUserListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CSortListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;

// 배경 브러시를 생성한다.
m_brushBackground.CreateSolidBrush(GetBkColor());

return 0;
}

BOOL CSearchUserListCtrl::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}

void CSearchUserListCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting

CMemoryDC memDC(&dc, &m_rtClientArea);
memDC->FillRect(&m_rtClientArea, &m_brushBackground);
CSortListCtrl::DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, 0);
}

void CSearchUserListCtrl::OnSize(UINT nType, int cx, int cy)
{
CSortListCtrl::OnSize(nType, cx, cy);

// 리스트 컨트롤의 영역 정보를 구한다.
GetClientRect(&m_rtClientArea);
}
위와같이 하면 컨트롤의 화면 깜빡임을 어렵지 않게 없앨 수 있다.
Read More