11월, 2019의 게시물 표시

sbrk(), brk() 메모리 할당(malloc) 시 호출되는 시스템 콜

참조 : https://en.wikipedia.org/wiki/Sbrk http://man7.org/linux/man-pages/man2/brk.2.html https://pubs.opengroup.org/onlinepubs/7908799/xsh/brk.html  메모리 관리에 사용되는 기본적인 시스템 콜 명령어 int brk(void * addr ); The  brk()  function sets the break value to  addr  and changes the allocated space accordingly. brk() 는 addr 주소 위치에  program break  (현재 프로세스의 data segment의 끝부분 바로 다음 자리)를 설정한다.  program break )를 설정한다.  program break 의 위치를 옮김으로써 메모리를 할당하거나 반환한다.  성공시 brk() 는 0을 반환하고 실패시 -1 을 반환한다. void *sbrk(intptr_t increment ); The  sbrk()  function adds  incr  bytes to the break value and changes the allocated space accordingly. If  incr  is negative, the amount of allocated space is decreased by  incr  bytes. The current value of the program break is returned by  sbrk (0).  sbrk() 는  program break 에 increment 만큼 더한 뒤 그만큼 할당된 메모리를 변경한다. 만약에 increment가 음수이면 할당된 메모리는 ...

낌새만 보이면 const를 들이대 보자

아이템 3 : 낌새만 보이면 const 를 들이대 보자 Const 는 상수 값을 선언하는 데 사용된다 . 여러 가지 용도로 사용되는데 , 상수 포인터 STL 의 const_iterator 함수 선언 - 함수 반환 값을 상수로 정해 주면 , 안전성이나 효율을 포기하지 않고도 사용자측의 에러 돌발 상황을 줄이는 효과를 꽤 자주 볼 수 있게 된다 .  1 2 3 4 5 6 7 8 9 10 class Rational {}; const Rational operator * ( const Rational& lhs, const Rational& rhs); //반환 값을 const 로 선언한 이유는 void DoSomething () { Rational a, b, c; (a * b) = c; //여기서 a*b의 결과에 두고 operator = 을 호출하는 것을 막기 위해 //const 라서 값 변경 불가능 } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 class TextBlock { public: TextBlock(std::string str) : text(str) {} const char & operator [](std:: size_t position) const { return text[position]; } //상수 객체에 대한 operator[] char & operator [](std:: size_t position) { return text[position]; } //비상수 객체에 대한 operator[] private: std::string text; }; void DoSomething2 ()...

공부 자료

공부자료 URL 모음 https://www.geeksforgeeks.org/commonly-asked-algorithm-interview-questions-set-1/ gfg - c++ 인터뷰 질문 모음 확인할 것. 객체 지향 절차지향 차이점 :  https://m.blog.naver.com/atalanta16/220249264429 c++ gof 디자인 패턴 예시 : https://github.com/JakubVojvoda/design-patterns-cpp 클래스 다이어그램 :  https://github.com/brodieroy/Study/wiki/(U)-UML-%ED%81%B4%EB%9E%98%EC%8A%A4%EA%B0%84-%EA%B4%80%EA%B3%84(association,-composition,-aggregation,-dependency) 유니티 알아두면 좋은 점 :  http://blog.naver.com/PostView.nhn?blogId=hana100494&logNo=221352372493&parentCategoryNo=&categoryNo=9&viewDate=&isShowPopularPosts=true&from=search 유니티 커스텀 타임라인 시그널  https://gametorrahod.com/how-to-make-a-custom-signal-receiver-with-emitter-parameter/ foreach랑 getenumertor 를 활용한 순환 방식이 어떻게 다른지 그리고 foreach에서 가비지가 발생하는 이유 https://m.blog.naver.com/PostView.nhn?blogId=dlwhdgur20&logNo=221015850179&proxyReferer=https%3A%2F%2Fwww.google.com%2F c# 메모리 누수 피하기  https://michae...

초기화 코드가 중복되는 것을 최소화하라

아이템 14 : 초기화 코드가 중복되는 것을 최소화하라 생성자 코드가 중복될 때, C++ 에서는 private 헬퍼 메소드를 작성하여 공용으로 사용하지만, C#에서는 공용 생성자를 이용하는 방법이 있다. C# 컴파일러는 공용 생성자를 이용하는 초기화 방식을 매우 특별한 문법으로 인식한다. 변수에 대한 중복 초기화 코드를 제거해줄 뿐 아니라 베이스 클래스의 생성자가 반복적으로 호출되는 것도 막아준다. 즉 객체 초기화를 위해 수행해야 하는 코드를 최적화해준다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 public class MyClass { private List< int > m_Data; private string name; //공용생성자 public MyClass () : this ( 0 , "" ) { } public MyClass ( int initCount) : this (initCount, string .Empty) { } public MyClass ( int initCount, string name) { m_Data = (initCount > 0 ) ? new List< int >(initCount) : new List< int >(); this .name = name; } } ...

정적 클래스 멤버를 올바르게 초기화하라

아이템 13 : 정적 클래스 멤버를 올바르게 초기화하라 정적 멤버 변수를 포함하는 타입이 있다면 인스턴스를 생성하기 전에 반드시 정적 멤버 변수를 초기화해야 한다. 이를 위해 C# 에서는 정적 멤버 초기화 구문과 정적 생성자라는 두 가지 기능을 제공한다. 정적 생성자는 타입 내에 정의된 모든 메서드, 변수, 속성에 최초로 접근하기 전에 자동으로 호출되는 특이한 메서드다. 인스턴스 멤버 초기화와 마찬가지로 정적 멤버를 간단히 초기화하는 경우라면 정적 생성자를 사용하기 보다는 멤버 초기화 구문을 사용하는 것이 좋다. 하지만 초기화 과정이 복잡하다면 정적 생성자를 사용하는 것도 나쁘지 않다.(생성자 안에 try catch 문은 넣을 수도 있다.) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public class MySingleton { //멤버 초기화 구문 사용 예 private static readonly MySingleton s_Instance = new MySingleton(); public static MySingleton Instance => s_Instance; private MySingleton () { } } public class MySingleton2 { //정적 생성자 사용 예 private static readonly MySingleton2 s_Instance; public static MySingleto...