기본 콘텐츠로 건너뛰기

라벨이 Kotlin인 게시물 표시

추천 게시물

[Go] 고루틴

런타임(Runtime) visual code에서 브라우저 실행 단축키: Alt+B Go runtime은 메모리 관리, 가비지 수집, 동시성을 포함하여 Go 프로그림의 실행을 관리하는 역할을 합니다. 이 문서에서는 Go runtime을 자세히 살펴보고 아키텍초, 특성과 장점을 살펴봅니다. Go Runtime Architecture Go runtime은 모듈식이고 유연하게 설계되었으며 개발자가 특정 요구사항에 따라 동작을 사용자 정의할 수 있는 계층적 아키텍쳐를 갖추고 있습니다. 런타임은 스케줄러(schedualer), 가비지 수집기(garbage collector), 메모리 할당자(memory alllocator) 및 스택관리(stack management)를 포함한 어려 핵심 구성 요소로 구성됩니다. Schedualer Go 런타임의 핵심은 고루틴의 실행을 관리하는 스케줄러입니다. 고루틴은 효율적인 동시성을 가능하게 하는 가벼운 스레드입니다. 스케줄러는 사용 가능한 스레드에 고루틴을 분산하고, 스레드 로컬 스토리지를 관리하고, I/O 작업을 조정하는 역할을 합니다. thread(스레드): 프로그램 내에서 실행되는 흐름의 단위로 동시에 여러 작업이나 프로그램을 실행하는 것입니다. 즉, 코드를 실행할 수 있는 각 단위를 스레드라고 합니다. 고루틴(goroutine): Go 언어로 동시에 실행되는 모든 활동을 의미합니다. 고루틴을 만드는 비용을 스레드에 비해 매우 적기 떄문에 경량 스레드라고 합니다. 모든 프로그램은 적어도 하나의 main() 함수라는 고루틴을 포함하고 고루틴은 항상 백그라운드에서 작동합니다. 메인함수가 종료되면 모든 고루틴은 종료됩니다. 그러므로 고루틴보다 main이 먼저 종료되는 것을 방지해야 합니다. Go 스케줄러는 매우 효율적이고 확장 가능하도록 설계되어 많은 수의 동시 고루틴을 손쉽게 처리할 수 있습니다. 스레드 간에 부하를 분산하여 경합을 최소화하고 성능을 개선하는 작업 훔치기 알고리즘을 사용합니다...

[kotlin]Smart Cast & Any type in Kotlin

Smart Cast In Kotlin, data types have the following meanings: 1) Define the size in which the object is stored 2) Whether objects are replaced or not. That is, they must have the same data type to execute. For example, the operation of Int type and Double type is not performed. val a: Int = 17 val b: Double= a println(b)      error: type mismatch: inferred type is Int but Double was expected                   val b: Double= a The assignment of a to object b is not done because the data types of objects a and b are different. When using a data type to which a smart cast is applied, the data type is specified according to the assigned value. The Number type is a data type to which a representative smart cast for numbers is applied. Therefore, if the Number type is applied in the above case, it is as follows. val a: Int = 17 val b: Number=a println(b)      17 In the code above, a is o...

Primitive and Reference type on kotlin

The Comparison between two objects  Comparison uses double equal sign (==) and triple equal sign (===) Double equal sign (==): Compares values. Triple equal sign (===): Compares the reference address. Kotlin's data type is basically a reference type, and basic data types such as Int and Double are converted at the compile stage. val a: Int = 128 val b: Int = 128 println(a == b)      true //Two objects have the same value. println(a === b)      true After compilation, both objects a and b are converted to primitives and stored in stack memory. Therefore, their storage locations are the same. val a: Int = 128 val c: Int? = 128 println(a == c)      true println(a === c)      false The data types of the two objects a and c above are Int and nullable Int, respectively. In the compilation phase, Int is converted to primitive type, but nullable Int remains as reference type. Therefore, Int is stored in s...