IT 취미생활.  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
'Programming/C++'에 해당하는 글(5)
2008.09.01   [C++]asio C++ library
2008.03.13   [C++ STL] size()의 결과를 0과 비교할 생각이라면.... 차라리 empty를 호출하자
2008.03.12   Tiny singleton helper class
2008.03.10   [펌]Tiny singleton helper class
2008.03.09   2차 배열 동적 할당 - 일반 및 개선 2


[C++]asio C++ library
크로스 플렛폼 C++ 라이브러리로써 네트워크와 저수준 I/O를 비동기 모델로 제공한다.


asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.

Download
asio - 1.2.0 (Stable)
Last Update: Aug 14 2008



SourceForge.net을 가다 보면 나름 좋은 프로그램들을 만날 수 가 있다.

그럼 고운하루 되세요

 



[C++ STL] size()의 결과를 0과 비교할 생각이라면.... 차라리 empty를 호출하자
Effective STL을 찬찬히 다시 읽고 있는 중입니다.
저도 나이를 하나씩 먹어감에 따라서 기억이 가물 가물 해지는군요.

가까운곳에 글을 남겨, 오래 기억 해야겠어요.
결국 밥줄이 이것 밖에 없는데...ㅜㅜ;


if( c.size() == 0 )
    dosomething();

보다는.....

if( c.empty() == 0 )
   dosomething();

이라 쓰는게 좋다 합니다. 이유는 모든 표준 컨테이너에 대해 상수 시간에 실행 된다고 하는군요.
몇몇에서는 list 클래스에 size가 선형 시간에 수행 되는 경우가 많다고 합니다.

STL도 무조건 좋다고 사용하는 것 보다.
하나 하나 성능과 효율을 측정하며 사용하는 건 프로그래머의 몫이 아닐까 합니다.

그럼 오늘도 즐프~


Tiny singleton helper class

Introduction

Sometimes we have to code with 'singleton'. If you don't know what Singleton is, you can read about it in many Design Pattern books. Singleton principle is really simple.

As you know, if you use reference pointer for singleton object, then you must delete it when program terminates. But it will be good because it does 'late instance'.

I want to terminate singleton object automatically, and instance lately. So, I coded this.

Good things:

  • Late instance.
  • Safe terminate automatically.
  • Separated code for Object and Singleton.

Here is my tiny singleton helper class - CSingletonT<>, and I hope it helps you.

//
// Using singletonT class
//
#include "SingletonT.h"
// test class
class CObj
{
protected:
    CObj(){ x = 0 ; TRACE("Created CObj\r\n"); }
public:
    virtual ~CObj(){ x = 0 ; TRACE("Deleted CObj\r\n");}
    int x;
};
// Testing
void CTestSingleTDlg::OnButton1()
{
    // TODO: Add your control notification handler code here
    // if first call, then singleton object will instance ( instance lately )
        CObj* o = CSingletonT<CObj>::GetObject();
    // use singletone object
    o->x ++;
    TRACE("o->x = %d\r\n",o->x);
}
------------------------------------------------------------------------------------
싱글톤에 조금은 벗어났지만,활용 할 수 있는 방법은 많다고 생각 됩니다.
원문을 보고 싶으시다면  아래로...
정확한 출처는 CodeProject 입니다.



http://www.codeproject.com/cpp/singlet.asp
우리 나라 분이 작성한 글입니다


[펌]Tiny singleton helper class

Introduction

Sometimes we have to code with 'singleton'. If you don't know what Singleton is, you can read about it in many Design Pattern books. Singleton principle is really simple.

As you know, if you use reference pointer for singleton object, then you must delete it when program terminates. But it will be good because it does 'late instance'.

I want to terminate singleton object automatically, and instance lately. So, I coded this.

Good things:

  • Late instance.
  • Safe terminate automatically.
  • Separated code for Object and Singleton.

Here is my tiny singleton helper class - CSingletonT<>, and I hope it helps you.

//
// Using singletonT class
//
#include "SingletonT.h"
// test class
class CObj
{
protected:
    CObj(){ x = 0 ; TRACE("Created CObj\r\n"); }
public:
    virtual ~CObj(){ x = 0 ; TRACE("Deleted CObj\r\n");}
    int x;
};
// Testing
void CTestSingleTDlg::OnButton1()
{
    // TODO: Add your control notification handler code here
    // if first call, then singleton object will instance ( instance lately )
        CObj* o = CSingletonT<CObj>::GetObject();
    // use singletone object
    o->x ++;
    TRACE("o->x = %d\r\n",o->x);
}
------------------------------------------------------------------------------------
싱글톤에 조금은 벗어났지,활용 할 수 있는 방법은 많다고 생각 됩니다.
원문을 보고 싶으시다면  아래로...
http://www.codeproject.com/cpp/singlet.asp
우리 나라 분이 작성한 글입니다.


2차 배열 동적 할당 - 일반 및 개선
일반 적인 2차 배열 동적 할당


코드:
template <typename Ty>
Ty **alloc2DArray(int width, int height)
{   
 Ty **arr = new Ty*[height];   
 for(int i=0; i<height; i++)   
 {       
  arr[i] = new Ty[width];  
 }   
 return arr;
}
template <typename Ty>
void free2DArray(Ty **&arr, int height)
{  
 for(int i=0; i<height; i++)   
 {       
  delete []arr[i];       
  arr[i] = 0;   
 }  
 delete []arr;   
 arr = 0;
}


고급
int **imatrix( int w, int h ) 
{
 int i;
 int **m;
 m = new int * [h]; 
 if( !m )
  PutError("memory alloc failure in imatrix()"), exit(0);
 m[0] = new int [ w * h ]; 
 if( !m[0] )
  PutError("memory alloc failure in imatrix()"), exit(0);
 for( i = 1; i < h; i++ ) { 
  m[i] = &m[0][ i * w ];
 }
 return m;
}

고급으로 할당 하는 방법에 대해서 눈여겨 보세요.


BLOG main image
취미생활
 Notice
 Category
분류 전체보기 (191)
매일매일갱생 (83)
서버개발 (1)
임베디드개발 (12)
Programming (80)
개발잡념 (10)
C (6)
C++ (5)
Java (4)
알고리즘 (5)
VC++ (11)
DirectShow (5)
OS (1)
Error Case (13)
Personal Projects (6)
유용한 프로그램 (0)
 TAGS
퇴사 Error Case debugging 1seg DirectShow Java M480 Wince5.0 개발자 MP3 ISDB-T english email Brazil English C Debug 군대 티스토리초대 warning 벨소리 변경 project VC++ 영어 이메일 Linux Algorithm 음식 C++ isdbt 알고리즘 DVB It 티스토리 초대장 Dshow 서태지 출장 미라지폰 spam mail Windows Mobile6.0 DVB-T
 Calendar
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
 Recent Entries
 Recent Comments
 Recent Trackbacks
 Archive
 Link Site
zextor
괴짜 프로그래머의 일상사~@@
Gag & Peace, and more..
Kazakhstan Almaty.......
Min-A
Sadgarret
Steve Yoon's log
가슴 뛰는 삶을 살아라
오스틴 파워
GUI sin
melanie parker_Lady
제레미의 TV 2.0 이야기..
 Visitor Statistics
Total :
Today :
Yesterday :
rss