MINERVA/C_CPP 2013. 10. 11. 13:01
반응형

이런 버그는 치명적인것 같다. hot fix를 하더라도, 기능을 수동으로 active를 해야 한다니..처음 인것 같다.

crash dump파일이 엉뚱한 곳을 찝고 있다니...

http://support.microsoft.com/kb/976038/en-us

http://www.devpia.com/Maeul/Contents/Detail.aspx?BoardID=51&MAEULNo=20&no=8700&ref=8700

일단 급하게 모든 프로그램을 patch해야 겠다.

반응형
posted by choiwonwoo
:
MINERVA/C_CPP 2013. 7. 1. 01:15
반응형

프러덕트에 적절한 라이브러리 찾다가, 참신한(?) 자료가 내용을 퍼왔습니다.

 

C++에서 Json을 사용할 일이 생기면서 C++에서 사용 가능한 Json Parser를 조사해 봤습니다.

조사결과 다음과 같은 파서가 존재했으며 간단히 특징을 기술해 보고 테스트 결과를 공유하고자 합니다.

 

조사 대상

라이브러리명 언어 기타
jsoncpp (강추) C++ 큰 무리 없이 사용 가능
jansson C

오래되고 안정적임.

단 C 언어라 코딩하기 귀찮음.

단, C언어로 개발해야 한다면 jansson을 쓰는 것이 제일 좋음.

json spirit C++ Boost Spirit library 사용. header only로 설치가 된다던데, 설치 포기.
MongoDB의 json parser C++

mongodb C++ driver에 내장됨. Mongo::fromjson()

mongodb C++ driver에 있으므로 따로 설치할 필요가 없으나, 사용하기는 좀 어려웠음.

UniversalContainer C++ 원래 목적은 PHP 등 스크립트 언어의 자료 구조를 지원하는 용도이나, json으로 encode, decode 가능.
설치 후 하는데 고생을 좀 했는데, 테스트 시 seg. fault가 나서 테스트 포기

 

각 라이브러리별 특징을 조사하면 다음과 같습니다.

 

jsoncpp

  • http://jsoncpp.sourceforge.net/
  • 큰 단점없이 사용 가능.
  • 단, library 빌드 시 -O2 가 안 켜져 있어서 직접 켜줘야 속도가 빠름. 안 그러면 PHP보다 느림.
    • library 소스에서 SConstruct 파일을 열어서 CCFLAGS = "-Wall"에 -O2를 추가하거나 scons로 --opt=-O2 주기.
  • key 순서가 알파벳 순서로 바뀌어 출력됨.
    {
        "k2":"xxx",
        "k1":"yyy"
      }

    의 문서 경우, json 문서를 탐색할 때 항상 k1이 먼저 접근됨.

  • key 순서 문제의 경우, http://sourceforge.net/tracker/?func=detail&atid=758829&aid=3014601&group_id=144446 를 참고하여 소스를 직접 바꾸면 된다고 하는데 아직 실험적인 방식이라 시도해 보진 못함.
  • UTF-8 문서를 읽는데 문제는 없으나, 출력 시 utf8 문자를 \uxxxx 형태로 출력하는 것은 안 됨. (읽을 때는 가능)

 

 

 

jansson

  • http://www.digip.org/jansson/
  • 만든지 오래되고 사용하는 곳도 많은 듯.
  • 단, C 언어라서 코딩하기가 귀찮음.
  • C언어로 개발할 때는 jansson을 사용하는게 제일 좋을 듯.
  • utf8 fully support
  • json object간에 reference count를 수동으로 기록할 수 있고, 메모리 관리를 개발자가 직접할 수 있음.
  • 그러나 이를 관리하기 위한 코딩이 좀 수고스러울 듯.

json spirit

  • http://www.codeproject.com/KB/recipes/JSON_Spirit.aspx
  • Boost Spirit library를 이용하여 만든 JSON Parser
  • header only로 설치 가능하다고 함.
  • utf8 지원
  • 본인은 library 설치가 잘 안 되고 특별한 장점을 찾기 못해서 더 이상 조사 안 함.

MongoDB의 JSON Parser

  • http://api.mongodb.org/cplusplus/2.0.2/namespacemongo.html#a4f542be0d0f9bad2d8cb32c3436026c2
  • mongodb C++ driver를 다운 받으면, Mongo::fromjson() method.
  • mongodb로 프로젝트를 하는 경우, BSONObj를 다룰 줄 알아야 하므로 json parser로 적당할 수도.
  • 단, 64MB 이상의 경우 parsing 하다가 에러 발생.
    • mongo/bson/util/builder.h 파일을 열어서 BSONObjMaxUserSize, BufferMaxSize의 값을 늘리면 해결 가능함.
  • json 파싱 시간은 느리지만, 메모리 사용량은 다른 것보다 적음. (Bson 형태이므로 압축 효과가 있어서 그럴 듯??)
  • JSON 문서가 항상 object로 시작하고 key가 있어야 함. 이건 좀 불편함.
    [{...}] <= object로 시작하지 않아서 안 됨.
      {"temp":[{...}]} 로 변환해야 함.
  • key에 _id가 항상 삽입됨....

UniversalContainer

  • http://greatpanic.com/progdocs/libuc.html
  • 원래 목적은 자료 구조를 PHP, Perl 처럼 쉽게 접근하기 위한 목적임.
  • 자료 구조를 JSON으로 serialize, de-serialize 가능함.
  • FlexLexer.h 파일 문제 때문에 컴파일이 안 되는데 인터넷 찾으면 설치는 가능함.
  • 어렵사리 설치를 했으나, 테스트 해 보면 seg. fault가 많이 발생.
  • 더 이상 테스트 포기
  • 복잡한 자료구조를 담고 사용하는데 편리해 보였는데 테스트 조차 못해서 아쉬움이 큼.
  • 그런데 jsoncpp로 복잡한 자료 구조를 담고 사용하는데 편해서 다행임.

성능 테스트

평가 결과는 각자 환경마다 다를 수 있으니 너무 맹신하진 마세요.

평가 대상

총 5개의 Library 중, 테스트 가능한 다음의 2개 + PHP가 테스트 대상임.

  • jsoncpp
  • janson
  • Mongo::fromjson
  • PHP

평가 환경

  • 입력 파일
    • 파일 사이즈 : 250MB
    • 2차원 array 형.
      [
        {....} <= depth 확장 없음. 총 190만개의 element가 있음.
        ...
        ...
        {....}
      ]
  • 평가 항목
    • parsing 시간
    • parsing 시 메모리 사용량
    • 탐색 시간 (각 element의 특정 key를 출력)

성능 평가 결과

구분 jsoncpp jansson PHP Mongo::fromjson
parsing 시간 10초 13초 10초 24초
메모리 사용량 1.4GB 1.3GB 2.5GB 800MB
탐색 시간 13.7초 13.8초 13.4초 N/A

결과에 대한 소고

 

반응형
posted by choiwonwoo
:
MINERVA/C_CPP 2012. 1. 17. 02:01
반응형
윈도우 어플을 개발하다보면, 콘솔로 로그를 찍으면서 개발을 하고 싶을 경우가 있다. 이런 경우 여러 가지를 방법을 시도 했지만, 두가지가 나에게는 베스트인것 같다.
 
1) 콘솔창 사용
http://www.halcyon.com/~ast/dload/guicon.htm
http://www.codeproject.com/KB/debug/mfcconsole.aspx

2) log4xx를 사용
기본기능으로 console기능 지원도 하지만, 로그에 대한 뷰여가 좋은 것들이 많아 콘솔과 같은 느낌을 준다.

cf) Unix/Linx에서 지원하던 tail이 윈도우로 mtail이라고 있지만, 내부 버퍼, 그리고 UI가 아직은 비호감이다.
반응형
posted by choiwonwoo
:
MINERVA/C_CPP 2011. 10. 12. 07:26
반응형


 


반응형
posted by choiwonwoo
:
MINERVA/C_CPP 2011. 5. 11. 01:16
반응형

매크로 상수 : _MSC_VER

1000 : Visual C++ 4.X
1100 : Visual C++ 5.0
1200 : Visual C++ 6.0
1300 : Visual C++ .NET
1310 : Visual C++ .NET 2003
1400 : Visual C++ .NET 2005
1500 : Visual C++ .NET 2008
1600 : Visual C++ .NET 2010

반응형
posted by choiwonwoo
:
MINERVA/C_CPP 2011. 2. 25. 07:18
반응형

Binding :
Binding means asociating the values to symbols in the program code. There are two type compile time ( Static !) and runtime (synamic)

1. Compile time bindings are done at compile time, thus all the symbols are resolved at compile time, This increases the compile time thugh u can see some run time performance increases ( generally its the load time). Here things are static and the code generated by compiler is ready to load at a relative memory area and the start executing.

2. runtime binding or dynamic binding, where the bindings are delayed to load time or run time. the symbols will be resolved at load time or run time so that the extern declarations and other external linking can be allowed. This may add small extra time in execution of the progrm ( May be loading ).

compile time binding is when datatypes are checked when the code is compiled

runtime binding is when datatypes are not checked until the compiled code actually runs and therefore requires the programmer to be more formal and strict in variable assignment


source : http://answers.yahoo.com/question/index?qid=20060722082832AAC4KKx
반응형
posted by choiwonwoo
:
MINERVA/C_CPP 2011. 2. 24. 08:02
반응형
요즘 깜빡 깜빡 까먹는데, 나 자신에게 놀란다. 그래서 나 자신을 위해서 기록하고자 한다.

-1의 HEX값은? 당연히 0xFFFFFFFF :
-2의 HEX값은? 단연히 0xFFFFFFFE :

이렇게 되는 이유를 짐작 못하신다면, 컴퓨터에서 정수형의 표현 가능한 범위를 생각한다면, 추측이 가능하실껏이다.

반응형
posted by choiwonwoo
:
MINERVA/C_CPP 2011. 2. 24. 07:53
반응형
오늘 지인으로 아래와 같은 질문을 받았다.

질문 : "본인이 Unix(solaris로 추정)에서 작업한 프로그램을 Linux로 포팅하고 있는데, ps -ef | grep "xxx"로 모니터링을 하면, 유닉스에서는 프로세스가 나왔는데, 리눅스에서는 각 thread가 나온다고 한다. 이거 이상하다?"

답변 : 이런 상황에 대해서 이전에 경험한적이 있어 아래와 같이 정리했다.
아시다 시피, Multi-thread programming을 할때는 각 OS별로 어떠한 형식의 Thread를 지원하는 숙지할 필요가 있다. 내가 기억하기로는, Kernel thread를 지원하는 것은 윈도우, solaris, 그리고 일부 Linux버젼(커널 버젼별로 차이가 있다.)이다. 그럼 좀 더 자세하게 살펴 보자.

1.  Process vs Thread
1.1 Process = code + data + stack + heap segment
1.2 Thread = stack + register , 그리고 나머지 code + data+ heap은 다른 thread와 공유한다. 특히 heap을 다른 thread와 공유하기 때문에, 동기화 이슈가 발생한다.

2. User thread란?
결론부터 말한다면, Kernel Thread보다 빠르다. 왜냐면, context switching(thread switching)이 Kernel level로 내려가지 않고, User mode에서 모두 처리가 된다.(즉 system call이 발생하지 않는다.) 그렇기 때문에 Kernel thread보다 빠르다.

또한, 일반적으로 학교에서 많은 종류의 thread scheduling algorithms(FIFO, FILO, RR etc)을 배웠다. 하지만 이러한 알고리즘은 OS에 종속적이고, 대부분의 OS가 RR을 사용하고 있는것으로 알고 있다. 하지만 때로는 내가 쓰레드 스케줄링 알고리즘을 선택하고 싶을때가 있다. 이것은 User Thread에서 가능하다. 이것이 가능한 이유는 User Thread를 구현하기 위해서는 POSIX와 같은 라이브러리가 필요한데, 이 라이브러를 통해서 이 스케줄링 알고리즘을 선택또는 변경 할수 있기 때문이다. 또한 thread의 생성과 관리가 빠르다.

하지만 문제점이 있다.
첫째: 커널 관점에서는 하나의 프로세스(또는 thread)에서 여러개의 thread가 동작하고 있다. 프로세스에서는 내부적으로 thread가 어떻게 돌아가는지 알수가 없다. 그래서 만약 하나의 thread가 blocking system call을 한 경우, 즉 하나의 thread가 non-blocking IO를 발생시키면, Kernel에서는 어느 thread가 이 call을 했는지 모른다. 이러한 thread sheduling에 대한 부분은 사용되는 라이브러리의 안정성과 성능에 달려 있다. 

둘째: Multi-cpu환경에서는 구조성 병렬성이 떨어진다. 좀더 자세하게 이야기하면, 프로세스는 CPU의 단위이다. OS는 각각의 프로스가 관리하는 thread들에 대한 내용을 모른다. 
 

3. Kernel Thread란?
모든 thread의 생성과 관리(스케줄링)가 OS에서 한다. 당연히 system call로 작업이 되기 대문에 User thread보다 성능이 않좋다(?).

장점: 개발등 관리가 편하다. 모든 것을 OS(윈도우, 솔라리스)에서 관리해주기 때문이다.
단점: 상대적으로 속도가 늦다.


반응형
posted by choiwonwoo
:
MINERVA/C_CPP 2009. 9. 24. 06:15
반응형

Introduction

Microsoft has put quite a lot of memory leak detection helpers in Windows NT. They have not done a good job of advertising it. This document describes some of the things I've deciphered while debugging code.

Funny Memory Values

Many times while debugging programs, I will come across memory that is filled with "funny" values. After some playing around (i.e. hacking) with the Win32 API, I was able to figure out what they meant. Some of these values have been documented in places but never all together. The values for the tags presented here are hexadecimal because that's the way Developer's Studio presents them in the memory window.
 Value  Meaning
 0xAB
or
 0xABAB 
or
 0xABABABAB 
 Memory following a block allocated by LocalAlloc().
 0xBAADF00D  Bad Food. Get it? This is memory allocated via LocalAlloc( LMEM_FIXED, ... ). It is memory that has been allocated but not yet written to.
 0xFEEE
 0xFEEEFEEE
 This seems to be memory that has been dedicated to a heap but not yet allocated by HeapAlloc() or LocalAlloc().
 0xCC
or
 0xCCCC
or
 0xCCCCCCCC
 Microsoft Visual C++ compiled code with the /GZ is automatically initialized the uninitialized variable with this value.
 0xCD
or
 0xCDCD
or
 0xCDCDCDCD
 Microsoft Visual C++ compiled code with memory leak detection turned on. Usually, DEBUG_NEW was defined. Memory with this tag signifies memory that has been allocated (by malloc() or new) but never written to the application.
 0xDD
or
 0xDDDD
or
 0xDDDDDDDD
 Microsoft Visual C++ compiled code with memory leak detection turned on. Usually, DEBUG_NEW was defined. Memory with this tag signifies memory that has been freed (by free() or delete) by the application. It is how you can detect writing to memory that has already been freed. For example, if you look at an allocated memory structure (or C++ class) and most of the members contain this tag value, you are probably writing to a structure that has been freed.
 0xFD
or
 0xFDFD
or
 0xFDFDFDFD
 Microsoft Visual C++ compiled code with memory leak detection turned on. Usually, DEBUG_NEW was defined. Memory with this tag signifies memory that is in "no-mans-land." These are bytes just before and just after an allocated block. They are used to detect array-out-of-bounds errors. This is great for detecting off-by-one errors.

http://www.samblackburn.com/
반응형
posted by choiwonwoo
: