BbaDdo :: 'cocos2d-x' 카테고리의 글 목록

'cocos2d-x'에 해당되는 글 2건

  1. 2021.06.04 소수 Prime Numbers 판별기 C++
  2. 2015.05.11 cocos2d-x 2.2.4 & 3.x : false positive, memory leaks

/*

 by ESP bbaddo 3.April.2021 

 입력범위 1 ~ 18,446,744,073,709,551,615 unsigned long long

*/

#include <stdio.h>

#include <iostream>

#include <sstream> 

#include <string>

 

using namespace std;

 

template <typename T>  //소수점12자리까지 문자열로 변환

string to_string_with_precision(const T value, const int n = 12)

{

ostringstream out;

out.precision(n);

out << std::fixed << value;

return out.str();

}

 

template <typename T>  //천단위 쉼표, 여기서 unsigned long long 만 쓰지만 템플레이트로 구현

string sep_thousands(const T value)

{

const char* locale_name = "english";

#ifdef WINDOWS

locale_name = "korean";

#endif

 

ostringstream out;

out.imbue(locale(locale_name));

out << value;

return out.str();

}

 

string checkPrimeNumber(unsigned __int64);

 

 

 

int main()  //실행 ctrl + F5

{

unsigned __int64 inputNumber = 0;

 

while(true)

{

cout << "******* 소수 prime number 판별기 *******" << endl;

cout << "입력 : ";

 

cin >> inputNumber;

//cout << inputNumber << endl; 

if (cin.fail()) {

//입력범위 1 ~ 4,294,967,295 unsigned int

//__int64(long long) -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807  unsigned long long  0 ~18446744073709551615

cout << "입력범위는 1 ~ 18,446,744,073,709,551,615 입니다." << endl; 

cin.clear();

cin.ignore(INT_MAX, '\n');  //clear all in the cin buffer --->문자 입력오류시

}

else if (0 == inputNumber)

{

cout << "종료합니다.\n" << endl; 

break;

}

else

{

cout << checkPrimeNumber(inputNumber) << endl;

}

 

inputNumber = 0;

cout << "\n0:종료\n" << endl;

}

 

system("PAUSE"); //실행 ctrl + F5

return 0;

}

 

 

 

string checkPrimeNumber(unsigned __int64 inputNumber)

{

unsigned __int64 sq = (unsigned __int64)sqrt(inputNumber);  //루트 중간값까지만 확인

if (0 == sq % 2) sq += 1;  //중간값이 짝수일 경우 큰홀수로 변경

//cout << "ROOT: " << sq << endl;

 

string str = "";

unsigned __int64 countNumber = 1;

 

if (1 == inputNumber) //입력숫자 1

{

str = to_string(inputNumber) + "은 소수가 아닙니다. ";

}

else if (3 == inputNumber) //입력숫자 3

{

str = to_string(inputNumber) + " 소수입니다! " + to_string(countNumber) + "루프 " + to_string_with_precision<double>((double)countNumber / inputNumber * 100) + "%";

}

else

{

if (0 == inputNumber % 2)  //짝수 일때

{

if (2 == inputNumber)  //입력숫자 2

{

str = to_string(inputNumber) + " 소수입니다! " + to_string(countNumber) + "루프 " + to_string_with_precision((double)countNumber / inputNumber * 100) + "%";

}

else  //나머지 짝수

{

str = sep_thousands<unsigned __int64>(inputNumber) + " 소수가 아닙니다. " + to_string(inputNumber / 2) + " X " + "2" + " = " + to_string(inputNumber);

}

}

else  //홀수 일때 215468423

{

for (unsigned __int64 i = 3; i <= sq; i += 2) //3이상 홀수만 확인

{

if (0 == inputNumber % i) //소인수 분해될때

{

str = sep_thousands(inputNumber) +" 소수가 아닙니다. " + to_string(inputNumber / i) + " X " + to_string(i) + " = " + to_string(inputNumber);

break;

}

else //루트 중간수 끝까지 확인했지만 소인수 분해가 안될때 --> 소수 

{

if (sq == i)

{

str = sep_thousands(inputNumber) +" 소수입니다! " + sep_thousands(countNumber) +"루프 " + to_string_with_precision((double)countNumber / inputNumber * 100) + "%";

break;

}

}

++countNumber;

}

}

}

return str;

}

'cocos2d-x' 카테고리의 다른 글

cocos2d-x 2.2.4 & 3.x : false positive, memory leaks  (0) 2015.05.11




결국 이제서야 코코스투디크로스 3.5 를 설치하고 설정하려니...

오래 전에 다 설치해놓고서 지금 다시보면 까마득.... 휘발성 대가리라 이렇게라도 기록해놓아야.

그리고 3.x 버젼은 렌더링을 새로 구현해서 기존 2.2 버젼보다 10배이상 빠르다고 한다.

spritebatchnode를 더 이상 쓸 필요가 없다고 함... 편해질 듯...

http://cocos2d-x.org/news/216


그런데 내부적으로 텍스쳐를 합쳐 새로 생성하는 기능이 없어졌다고 하는 듯 하는데 아직 확인을 못했다.

아직 안해봐서 그게 그건지 모름. 설마 아니겠지.

그래서 가장 안정적인듯한 2.2.3을 필요에 따라 번갈아 써야 할 듯. 공짜엔진이니까 아무래도 좋아요. 쐐쐐~


cocos2d-x 2.2.4 이상, 3.x에서 발생되는 메모리릭...

같은 코드인데도 2.2.3에서는 전혀 생기지 않았는데 발생된 기억이 난다.

4 byte 릭은 원래 생긴다는데 엔진코드를 살짝 바꾸면 없어짐.

기본 helloworld에서도 우루루 쏟아지는 메모리릭들이 vs에서 잘못 찾은 것이라고들 한다.


가양성 false positive...

  _CrtDumpMemoryLeaks can give false indications of memory leaks." data-guid="c58c57db8b6accd93a89a674a63ef875"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">간혹 _CrtDumpMemoryLeaks가 메모리 누수를 잘못 표시하는 경우도 있습니다.</sentencetext>  _CRT_BLOCKs or _CLIENT_BLOCKs." data-guid="d05cd00ff2d5e636da4397a2f7e83f46"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">이러한 오류는 내부 할당을 _CRT_BLOCK이나 _CLIENT_BLOCK 대신 _NORMAL_BLOCK으로 표시하는 라이브러리를 사용할 때 발생할 수 있습니다.</sentencetext>  _CrtDumpMemoryLeaks is unable to tell the difference between user allocations and internal library allocations." data-guid="309a37b28f5798b796144f756b6ae2df"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">이 경우 _CrtDumpMemoryLeaks가 사용자 할당과 내부 라이브러리 할당을 구별할 수 없게 됩니다.</sentencetext>  _CrtDumpMemoryLeaks, every internal library allocation is reported as a memory leak." data-guid="68e43a7af600c5b0e4135934898a4992"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">_CrtDumpMemoryLeaks를 호출한 이후에 라이브러리 할당을 위한 전역 소멸자가 실행되면 모든 내부 라이브러리 할당이 메모리 누수로 보고됩니다.</sentencetext>  _CrtDumpMemoryLeaks to report such false positives, but this has been fixed in recent releases." data-guid="cf7710ded385efefa5cd9a5292c36b5b"><sentencetext style='font-family: "Malgun Gothic", Gulim, "Segoe UI", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif !important;' xmlns="http://www.w3.org/1999/xhtml">Visual Studio .NET 이전 버전의 표준 템플릿 라이브러리에서는 _CrtDumpMemoryLeaks가 이러한 가양성(false positive)을 보고했지만, 최신 릴리스에서는 이 문제가 해결되었습니다.</sentencetext>

 

 

https://msdn.microsoft.com/ko-kr/library/x98tx3cf.aspx





1. 일반적인 메모리릭 검사방법

win32/main.cpp 


#if defined( DEBUG ) || defined( _DEBUG )

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#endif // DEBUG

 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR    lpCmdLine, int nCmdShow)
{

#if defined( DEBUG ) || defined( _DEBUG )
 //_CrtSetBreakAlloc(95832); //중단점
 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);


 // int *nData = new int;   //메모리릭 테스트
 // int *nData =(int*) malloc(16);
 // _CrtDumpMemoryLeaks(); //실시간 콘솔출력
#endif // DEBUG

 

// UNREFERENCED_PARAMETER( hInstance ) ;
 UNREFERENCED_PARAMETER(hPrevInstance);
 UNREFERENCED_PARAMETER(lpCmdLine);
 // UNREFERENCED_PARAMETER( nCmdShow ) ;


 // create the application instance
 AppDelegate app;
 return Application::getInstance()->run();


}


2. Visual Leak Detector를 이용한 메모리릭 검사방법

다운로드 홈페이지: https://vld.codeplex.com/releases

단점은 컴파일 속도가 조금 느려짐.

현재 최신버젼인 2.4rc2만 vs2013, 2012에서 작동확인.

RC버젼이라 아직 정식이 아니지만 잘 돌아가니 그냥 씀.


설정방법은 아래와 같이 간단.

main.cpp



#if defined( DEBUG ) || defined( _DEBUG )


#include <vld.h> 


#endif // DEBUG


최신버젼을 설치하면 자동으로 윈도우 환경변수와 vs 라입 링크를 걸어줌.

다만, include 경로는 수동으로 설정해주어야 함.

프록젝트 오른쪽클릭> 속성 > c/c++> 일반> 추가포함디렉터리>편집>c:\Program Files (x86)\Visual Leak Detector\include 추가


검사가 잘되는지 확인방법은

char *p = (char *)malloc(sizeof(char)* 1000);

이런 코드를 클래스내 아무곳에나 추가해서 확인.


vld를 제거하고 싶은 경우는 설치된 폴더로 가서 uninstall 하면 됨. 누구신지 모르지만 잘 만들었다. 


설치 참고 사이트 : http://choorucode.com/2010/09/11/visual-leak-detector-investigate-memory-leaks-in-visual-c/







끝.

'cocos2d-x' 카테고리의 다른 글

소수 Prime Numbers 판별기 C++  (0) 2021.06.04
1 

카운터

Total : / Today : / Yesterday :
get rsstistory!