A Nim está mudando para modelos de gerenciamento de memória mais eficientes: ARC e ORC. Vamos descobrir exatamente como eles vão mudar a maneira como funciona com a memória.
Introdução
Olá! Neste artigo, tentarei explicar o que sĂŁo ARC e ORC e ​​como eles afetarĂŁo o desempenho ou outras partes do Nim. NĂŁo vou mergulhar profundamente nos aspectos da parte do software, mas vou tentar dar uma explicação mais ou menos de alto nĂvel.
GC Nim refc
( mark & sweep ), , markAndSweep
, boehm
, go
, regions
.
Nim' , , (owned ref) :
, Nim ARC
ARC?
ARC , (Automatic Reference Counting) (move semantics). , ARC Nim , ARC Swift, — Nim ARC .
. ( runtime) , . , .
ARC GC Nim , ARC — (, , , .), . ARC C++ (RAII)
, , ARC expandArc
, Nim 1.4.
Nim:
proc main =
let mystr = stdin.readLine()
case mystr
of "":
echo "!"
of "":
echo "!"
quit()
else:
discard
main()
nim c --gc:arc --expandArc:main example.nim
.
--expandArc: main
var mystr
try:
mystr = readLine(stdin)
case mystr
of "":
echo ["!"]
of "":
echo ["!"]
quit(0)
else:
discard
finally:
`=destroy`(mystr)
-- end of expandArc ------------------------
— Nim main
try: finally
( finally
, try
) =destroy
mystr
, .
ARC: (scope-based MM). — . , , , . Nim' : , , , , block
, for
while
.
ARC hooks — , , // . , , , FFI.
refc
ARC ( ):
( ) — .
— , .
—
refc
, (thread-local heap), ARC . — . RFC , ARC.
FFI — ,
refc
"" (.. ) , ARC. , ARC , (.dll, .so, Python' )
-
(copy elision), Nim (cursor inference) — ()
, ARC Nim , , , .
, ARC , , , --gc:arc
, (.nims
.cfg
).
! - ? ARC , , , . — , , . : 3 (A, B, C), , :
, , — , , .
Nim' mark & sweep refc
GC, ARC - . :
ORC — Nim
ORC , ARC. GC, (local tracing phase) GC, (global tracing).
async Nim ORC, Nim' , .
ORC ARC () — ORC , hard realtime ( ) — .
ORC --gc:orc
, , ORC GC Nim'
! ?
— — Nim 1.4. .
! — , !
/ :
- Introducing --gc:arc
- Update on --gc:arc
- New garbage collector --gc:orc is a joy to use.
- Documentação oficial sobre destruidores e semântica de movimentos
- FOSDEM 2020 - mover semântica para Nim
- NimConf 2020 - Nim ARC / ORC
- Comunidade Nim
- RFC: Combine opções de gerenciamento de GC / memória no Nim