본문 바로가기
반응형

CPP9

[c++] RapidJson 사용하기, c++에서 JSON 파싱하기 JSON은 key, value 쌍으로 이루어진 데이터의 집합입니다. 웹에 데이터를 전송하거나, 간단한 구성 파일을 작성하는 데 주로 JSON 파일이 사용되곤 합니다. 물론 다양한 JSON 파싱 라이브러리가 있지만, 특히 RapidJson 라이브러리는 아래와 같은 장점이 있습니다. 1. 외부 라이브러리를 사용하지 않고 그냥 header 파일만 include 경로에 포함시키면 빌드할 수 있습니다 2. MIT 라이선스를 따르므로 상업적으로 사용하기 쉽습니다 RapidJson을 사용하기 전에 간단히 JSON에 대해 이해해봅시다. 먼저 JSON 문자열을 구성하는 두 가지 기본 데이터 포맷이 있습니다. (JSON object와 JSON array) 먼저 JSON object는 다음의 특징을 가집니다. * 중괄호 {.. 2023. 9. 13.
gitignore 파일 생성하기 (cmake, python, c++, c#) 결론부터 말하면 아래 사이트에 들어가서 사용하는 플랫폼을 입력하고 생성하기만 하면된다. (너무 편하다....) https://www.toptal.com/developers/gitignore gitignore.io Create useful .gitignore files for your project www.toptal.com ---- 프로그램을 빌드하다보면 빌드의 부산물 같은 게 생기는 데, python의 __pycache__나 c#, c++의 각종 오브젝트 파일, cmake의 cmakecache 같은 파일들이 그것들이다. 대게 빌드하는 시간을 줄이기 위해 생성되는 임시 파일에 해당하는 것들이다. git 저장소에 이런 파일들이 같이 올라가게 된다면 다른 개발 환경에서 코드를 받은 사람들은 빌드가 안될 수도.. 2021. 8. 5.
[c++] lvalue reference and rvalue reference lvalues references and rvalues references in C++ with Examples - GeeksforGeeks l-value and r-value l=value는 객체를 가리키는 메모리 위치를 나타내고, r-value는 메모리 위치에 할당된 값을 나타냅니다. 여기서 참조 (reference)는 이미 존재하는 변수에 다른 이름을 할당하는 것외에 다른 기능은 없습니다. int a = 10; int& lref = a; // 좌측 값 참조 int&& rref = 10; // 우측 값 참조 아래 코드는 좌측 값 참조와 참조된 변수의 주소를 비교하는 코드입니다. 마치 포인터처럼 같은 메모리 주소를 갖는 것을 알 수 있습니다. #include using namespace std; // .. 2021. 8. 4.
[c++] std::shared_mutex en.cppreference.com/w/cpp/thread/shared_mutex std::shared_mutex - cppreference.com class shared_mutex; (since C++17) The shared_mutex class is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads. In contrast to other mutex types which facilitate exclusive access, a sh en.cppreference.com 상호배타적인 다른 mutex들과 달리 shard_mutex는 공유 자.. 2020. 12. 16.
[c++] std::recursive_mutex (std::mutex 비교) 일반적으로 mutex의 lock을 두 번 호출하면 무한 대기 상태에 빠지지만, recursive mutex는 lock을 여러 번 호출해도 문제가 없다 lock을 호출하는 동안은 계속 소유권을 가지고 있다가 lock을 호출한 횟수 만큼 unlock을 호출하면 소유권을 해제하기 때문이다 재귀함수를 만들어보면 쉽게 이해할 수 있다 (이름부터 recursive_mutex) 한 번 재귀함수를 병렬처리해보자 그냥 mutex를 사용했을 때 (무한 대기) worker 함수를 호출하는 4개의 스레드를 생성한다 worker 함수는 자기 자신을 다시 호출하는 재귀 함수로 구성한다 result라는 공유자원에 다른 스레드가 접근하지 못하도록 mutex lock을 수행한다 worker 내부에서 worker 함수를 다시 호출하므로.. 2020. 12. 16.
[c++] std::mutex en.cppreference.com/w/cpp/thread/mutex std::mutex - cppreference.com class mutex; (since C++11) The mutex class is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads. mutex offers exclusive, non-recursive ownership semantics: A calling thread owns a mut en.cppreference.com mutex는 여러 스레드의 공유 자원을 보호하기 위해 사용되는 클래스입니다. std::mute.. 2020. 12. 16.
[c++] any any std::any: How, when, and why | C++ Team Blog 임의의 사용자 데이터 저장하기 다른 개발자에게 달력 라이브러리를 배포한다고 생각해봅시다. 하루 일정은 한 주 일정에 포함되고, 다시 한 주 일정은 월 일정에 포함되어야 할 것입니다. 그리고 각 일정마다 일일 계획 또는 한 주 계획을 저장할 수 있도록 크기가 정해지지 않은 데이터 (user data)를 담을 수 있는 데이터 구조를 만들어야 합니다. 아마 C 개발자라면 임의의 데이터를 받기 위해 void 포인터를 이용할 것입니다. struct day { // ... void* user_data; }; struct month { std::vector days; void* user_data; }; some_day.user_d.. 2020. 12. 15.
[c++] async en.cppreference.com/w/cpp/thread/async std::async - cppreference.com (1) (since C++11) (until C++17) template std::future , std::decay_t ...>> async( Function&& f, Args&&... args ); (since C++17) (until C++20) template< class Function, c en.cppreference.com async는 일종의 함수 템플릿 (function template)입니다. async를 사용하면 함수 f를 비동기적으로 실행하고 함수 f의 반환 값을 std::future로 반환합니다. 2020.. 2020. 12. 15.
[c++] future https://en.cppreference.com/w/cpp/thread/future std::future - cppreference.com template class future; (1) (since C++11) template class future ; (2) (since C++11) template class future ; (3) (since C++11) The class template std::future provides a mechanism to access the result of asynchronous oper en.cppreference.com 클래스 템플릿 (class template)인 std::future는 비동기적 수행 (asynchrono.. 2020. 12. 15.
반응형