boost
-
boost/asio deprecated 1.69.0프로그래밍/c++ - boost::asio 2019. 3. 11. 04:44
boost::asio가 c++ 표준에 들어가게 되서 그런지 변경 사항들이 많다.호환성을 위해 더이상 더이상 사용되지 않는 코드들이 여전히 남아있지만,전처리기에 BOOST_ASIO_NO_DEPRECATED를 지정하면 더이상 사용되지 않는 코드들이 비활성화 된다. io_service가 io_context로 이름 변경io_context::dispatch가 dispatch 로 대체 됨io_context::post가 post 로 대체 됨io_context::strand::wrap이 bind_execuator 로 대체 됨io_context::get_io_context(), io_context::get_io_service()가 context() 함수로 이름 변경.io_context::strand::get_io_con..
-
boost/asio simple periodic timer프로그래밍/코드 조각 2019. 3. 4. 12:28
#include #include #include class PeriodicTimerExample{public: PeriodicTimerExample() : timer{ctx} { } void run() { tick(); ctx.run(); } private: void tick() { using namespace std; timer.expires_after(3s); timer.async_wait([this](const auto & err) { cout
-
boost::asio dynamic buffer프로그래밍/c++ - boost::asio 2018. 5. 1. 14:06
asio에 dynamic_buffer라는 것이 추가되었다.asio::streambuf와 비슷하지만, 기존의 stl 컨테이너(std::vector, std::string 등)을 래퍼런스로 받아 조작하는 어뎁터 클래스이다.사용 방식은 다음과 같다. #include #include int main(){ using DynamicBuffer = boost::asio::dynamic_vector_buffer; std::vector buffer; DynamicBuffer dynamicBuffer = boost::asio::dynamic_buffer(buffer); return 0;} api도 기존의 asio::streambuf와 흡사하며 메모리를 공간을 확보, 반환해주는 prepare 함수의 경우 다음과 같이 구현되..
-
boost 의존성 없이 사용하기. asio standalone프로그래밍/c++ - boost::asio 2018. 4. 7. 19:20
asio를 boost 의존성 없이 단독으로 사용할 수 있다. 0. https://think-async.com/Asio/Download에서 asio를 다운 받는다.1. asio 소스를 프로젝트 내에 포함한다.2. 전처리기를 정의한다. #define ASIO_STANDALONE 그러면 boost가 아예 없어도 asio를 사용할 수 있다. ASIO_STANDALONE이 정의가 없으면 boost 의존성이 있으므로 주의!! boost::system::error_code -> asio::error_code 등으로 바뀌는 것들도 있다.
-
boost::variant(std::variant c++17) 사용하기프로그래밍/c++ 2016. 8. 5. 03:38
boost::variant는 n개의 타입이 될 수 있는 타입이다. boost::any와의 차이점은 지정된 형태로만 될 수 있으며 any와는 다르게 타입 변환 시 동적 할당을 사용하지 않기 때문에 퍼포먼스가 좀 더 뛰어나다. boost::variant는 n개의 타입이 될 수 있는 타입이다. union의 c++판 업그레이드 버전 정도 되는 라이브러리라고 생각해도 괜찮다. 또, c++17에 표준으로 포함 되었으며 c++ 관련 커뮤니티에서의 반응도 긍정적이다. 일단 사용하는 방법이 깔끔하고 쉬우니까.코드 >>#include boost::variant var; // setvar = 0.01;var = 123;var = "hello"; // getstd::string s = boost::get(var); 값을 얻을..
-
boost::any에서의 unsafe_any_cast프로그래밍/c++ 2016. 6. 6. 22:54
any_cast는 유도리가 없다. int로 넣은 것을 size_t로 읽으려고 하면 예외를 던진다. 실제 코딩을 함에 있어서도 int => unsigned int size_t => int같은 변환은 빈번한데, 안전한 캐스팅만을 보장해주는 any_cast가 야박하고 느꼈다면 unsafe_any_cast의 사용을 고려할 만 하다. 함수 시그니쳐 12345template const ValueType* unsafe_any_cast(const boost::any* operand) template ValueType* unsafe_any_cast(boost::any* operand)cs 사용 12345boost::any val = 1; boost::any_cast(val); // error! boost::unsafe_..
-
boost::pool_allocator와 boost::fast_pool_allocator의 차이프로그래밍/c++ 2016. 2. 28. 08:23
boost 1.6 버전 기준이다. boost::pool_allocator는 정렬된 할당/해제를 사용하는 반면, boost::fast_pool_allocator는 정렬되거나 정렬되지 않은 할당/ 정렬되지 않은 해제를 사용한다. 정렬되지 않은 할당/해제는 메모리 노드의 끝 부분에 메모리를 하나 추가하면 그만이지만,정렬된 할당/해제의 경우 이전 메모리를 찾는 과정이 필요하고 이 부분에서 부하가 생길 수 있다.다만 정렬된 할당/해제의 경우 연속된 메모리(가변, new int[10]과 같은!)를 지원하기 때문에 사용처에 따라 잘 구분을 해야할 것이다. boost::pool_allocator의 allocate / deallocate 123456789101112131415161718192021222324// pool..
-
boost/pool을 멀티 스레드 환경에서 제대로 활용하려면..프로그래밍/c++ 2016. 2. 28. 05:56
boost::pool_alloc과 boost::singleton_pool boost/pool은 멀티 스레드 환경에서 느리다는 인식이 있다. boost::pool_alloc은 내부적으로 boost::singleton_pool을 사용하며, singleton_pool은 멀티 스레드 환경에서의 동기화를 위해 할당/해제에 스레드 락이 있기 때문에 할당 테스트에서는 기본 메모리 할당자보다 안 좋은 퍼포먼스를 보이지만, 할당=>해제=>할당 식으로 테스트를 한다면 기본 할당자보다는 좋은 성능을 보인다. 그렇다면 일단 전역적인 풀로도 ok다. 풀이 필요한 환경이라면 어차피 할당=>해제=>할당=>해제 의 과정이 빈번하기 때문인데 이러한 환경에서는 전혀 문제될 것이 없음을 의미한다. 그럼 일단 singleton_pool은 ..