Language Study

공유 객체 여러 개의 스레드가 동일한 객체를 참조 및 공유하고 있을때, 해당 객체를 공유객체 공유 변수 사용하기 💡 ReentrantLock이나 Synchronized키워드 없이 번갈아가려고 하면 ”공유변수” 를 사용하면 된다. Busy Waiting이나 Spinlock과 같은 형태를 포함할 수 있기 때문에 CPU 자원을 비효율적으로 사용할 수도 있다. 또한 코드의 복잡성을 증대시키고, 잘못할 경우 데드락(Deadlock)이나 라이브락(Livelock)과 같은 문제를 일으킬 수 있다. public class WorkObject { private static int counter = 0; private volatile int turn = 1; public void methodA() { for (int i ..
Command Line이란? 컴퓨터의 텍스트 인터페이스 프로그램은 커멘드를 통해서 실행을 위해 컴퓨터 operation system으로 이동한다. Commend Line arguments - parameters that are supplied to the program when it is invoked argc & argv[] int argc // argument count commend line arguments의 char *argc[] // argument vector The array of the pointers to all command line arguments All command line arguments are inputted as character strings argv[0] points..
Index C 언어의 두 가지 파일 유형 Text File vs Binary File 파일 사용의 개골적 과정과 FILE 구조체 1. C언어의 두가지 파일 유형 Text Mode File vs. Binary Mode File 2. Text File vs Binary File C 언어에서는 파일을 읽거나 쓰기 위해 Open 할 때 대상 파일이 Text File 인지 Binary File 인지 구분하여야 한다. Text File 사람들이 읽을 수 있는 문자로 모든 정보를 표현하고 저장하는 파일 서로 다른 값을 구분하는 구분자가 필요하다 표준 입출력에 문자열을 출력하는 puts(), printf() 등의 함수,입력하는 gets(), scanf()등의 함수에 대응하는 fputs(), fprintf(), fget..
Index 변수(또는 메모리 블록) Lifetmie 분류 Memory Layout of a C Process 함수 호출과 Stack Automatic Variable & Stack 1. 변수(또는 메모리 블록) Lifetime 분류 ① Static Its lifetime is the entire duration of the program's execution Global and Static Local Variables A static variable is stored in the data segment of the "object file" of a program ② Automatic An automatic variable has a lifetime that begins when program execut..
① whlie문을 활용해볼까요. 1) 사용자가 Ctr - z를 눌러 EOF를 입력할 때까지 최대 MAX_LINES 만큼의 문자열을 입력받음 2) EOF인 경우 gets()의 return은 NULL이다. ② gets_malloc()을 사용해볼까요. 불필요한 메모리 사용을 줄이기 위해 문자열 입력을 위한 버퍼를 동적으로 할당. ※ gets_malloc() gets() 함수의 문자열을 입력 받을 버퍼를 malloc()으로 동적 할당 입력이 EOF이면 동적으로 할당 받ㅇ느 버퍼를 해제하고 NULL 을 Return 문자열 입력 버퍼 동적으로 할당 받는 문자열 입력 버퍼들을 관리하기 위한 문자열 포인터 배열 str_ptrs[]선언하고 NULL값으로 초기화 실제 입력 LINE 수에 해당하는 문자열 버퍼만 할당 동적으..
목차 정적인 메모리 공간 할당의 한계 동적인 메모리 할당 및 해제 함수 assert 매크로 메모리 공간의 할당과 복사 1. 정적인 메모리 공간 할당의 한계 만약 이 코드에서 1의 값을 100이라 했을 때 만약에 입력한 값이 150이면 run-time error 가 발생하고, 10을 입력했다면 메모리를 불필요하게 낭비한게 됨 → 필요한 크기를 미리 알 수 없다!! 면... 2. 동적인 메모리 할당 및 해제 함수 Dynamic Memory Management Functions Defined in header 메모리 동적 할당 함수 void *malloc(size t, size); Allocates size bytes of uninitalized storage Param: size - number of byt..
지미닝
'Language Study' 카테고리의 글 목록