전체 글 269

[Boost] 문자열 다루기

boost 에서 문자열을 다루는 방법을 알아본다. boost::lexical_cast 정수형 실수형 값을 문자열로 바꾸거나 반대로 문자열을 정수형, 실수형 값으로 변환할 때 사용한다. 기본 사용 문자열에서 값으로 변환하기, 타입으로 넘겨준다. auto i = boost::lexical_cast("100"); char chars[] = { 'x', '1', '0', '0', 'y' }; auto i2 = boost::lexical_cast(chars + 1, 3); 해당 변수에 담을 수 없는 값으로 변환하거나 변환이 불가능하다면 boost::bad_lexical_cast를 던진다. try { auto sh = boost::lexical_cast("100000"); } catch (const boost::b..

C++/Boost 2022.08.21

[Boost] thread

boost thread 사용법을 알아본다. 대부분의 기능은 C++11에 표준화되어 헤더에 포함되어 있다. 필요 헤더 #include thread 사용하기 static bool is_first_run() { return true; } static void fill_file(char fill_char, std::size_t size, const char* filename); static void p_example() { if (is_first_run()) { boost::thread(boost::bind(&fill_file, 0, 8 * 1024 * 1024, "save_file.txt")).detach(); } } 실행하고자 하는 함수를 전달하여 스레드를 만들어 실행하도록 한다. detach()는 프로그램..

C++/Boost 2022.08.21

[Boost] any / variant / optional

boost::any C#, JAVA와 같이 모든 타입을 지칭할 수있는 타입을 제공한다. 필요 헤더 #include 모든 타입을 담을 수 있는 클래스 void example2() { boost::any variable(std::string("Hello World!")); // if casting failed, may throw boost::bad_any_cast string s1 = boost::any_cast(variable); // if casting failed, s2 is null string* s2 = boost::any_cast(&variable); } 값에 대한 any_cast는 타입이 맞지 않을 시 boost::bad_any_cast를 던진다. 포인터에 대한 any_cast는 null로 대체..

C++/Boost 2022.08.20

[Boost] program_options

boost의 program_options을 사용해본다. 프로그램 시작 인수를 ./program.exe --option=value 과 같이 실행하고 필요 정보를 출력할 수 있게 해준다. 필요 헤더 #include 사용 방법 1. options_description 개체를 정의를 해준다. 2. 프로그램 인수를 파싱한다. 3. 프로그램 인수를 적용한다. 특징 options_description의 add_option()을 할 때 인수를 필수로 지정하거나 기본값을 지정하는 등을 할 수 있다. ./program.exe --help를 통해 옵션 정보를 출력할 수 있다. .cfg 파일을 통해 인수를 설정할 수 있다. #include "global.h" #ifdef _DEBUG #pragma comment(lib, "l..

C++/Boost 2022.08.20

[Boost] 라이브러리 설치

C++ 고급 기능을 사용할 수 있는 boost 라이브러리를 설치해본다. https://www.boost.org/ Boost C++ Libraries Welcome to Boost.org! Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications www.boost.org 공식 사이트 기준 boost 1.80.0 버전을 사용할 수 있다. 라이브러리 소..

C++/Boost 2022.08.20

[C++] Redis 사용하기

C++ Redis 라이브러리를 사용해본다. Redis 데이터 베이스 서버에서 쿼리로 조회하는 것보다 캐시 서버(Redis)를 둬 I/O를 동반한 데이터 베이스 서버보다 빠르게 데이터를 가져오기 위해 사용한다. 기본적으로 key-value 쌍의 데이터를 저장한다. Redis 는 C언어로 작성된 hiredis 라이브러리를 의존하는 C++ 라이브러리를 사용할 예정이다. C hiredis https://github.com/redis/hiredis GitHub - redis/hiredis: Minimalistic C client for Redis >= 1.2 Minimalistic C client for Redis >= 1.2. Contribute to redis/hiredis development by crea..

Advanced C++ 2022.08.18

[C++] CryptoPP 암호화/복호화 라이브러리

CryptoPP 라이브러리를 사용해본다. https://www.cryptopp.com/ Crypto++ Library 8.7 | Free C++ Class Library of Cryptographic Schemes hash functions BLAKE2b, BLAKE2s, Keccack (F1600), SHA-1, SHA-2, SHA-3, SHAKE (128/256), SipHash, LSH (128/256), Tiger, RIPEMD (128/160/256/320), SM3, WHIRLPOOL www.cryptopp.com SHA(Secure Hash Algorithm) 해시 함수 미 국가보안국(NSA)에서 개발한 암호화 해시 생성 알고리즘으로 Merkle–Damgård construction 에 기반..

Advanced C++ 2022.08.11

MySQL 실행 계획

MySQL 통계 정보 이용하기 1. 히스토그램 8.0 이상 버전 부터 사용할 수 있는 통계 정보. 쿼리의 실행 계획을 세우는데 도움을 준다. 컬럼 단위로 수집되며 ANALYZE TABLE ... UPDATE HISTOGRAM 명령을 실행해 수동으로 수집 및 관리된다. 예시) ANALYZE TABLE employees.employees UPDATE HISTOGRAM ON gender, hire_date; SELECT * FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME='employees' AND TABLE_NAME='employees'; gender 컬럼에 생성된 히스토그램 내용 {"buckets": [[1, 0.6000515237677232], ..

DB/MySQL 2022.06.12

Java 스레드

Java에서 쓰레드를 생성하는 방법 1. Runnable 인터페이스를 구현한 객체를 Thread 객체 생성자로 전달한다. private void ExampleThread() { class Task implements Runnable { @Override public void run() { } } Thread t1 = new Thread(new Task()); t1.start(); Thread t2 = new Thread(new Runnable() { @Override public void run() { } }); t2.start(); } - 인터페이스 객체는 run()이라는 메서드를 구현하고 실제 바탕 작업을 의미한다. - Runnable 인터페이스를 상속하는 익명 클래스를 전달한다. start()는 스..

언어 지식/Java 2022.06.08

(6) Pthread 쓰레드 / PMutex 뮤텍스

Pthread 사용하기 gcc -pthread thread_example.c -o thread_example.o -pthread 플래그로 링크해야한다. 스레드 생성하기 #include int pthread_create(pthread_t* thread, const pthread_attr_t *attr, void* (*start_routine) (void*), void* arg); thread : 생성된 스레드 ID를 반환 attr : 새로 생성할 스레드의 속성을 지정 start_routine : 스레드가 수행할 함수 arg : 수행할 함수에 전달될 인자 스레드 종료 및 취소 void pthread_exit(void* retval); int pthread_cancel(pthread_t thread); 스레드..

C++/linux 2022.05.12