Avoid memory fragmentation in Swift

GC compaction, sweep and mark prevent heap memory fragmentation. So how to avoid memory fragmentation in Swift?

Are these statements correct?

  • Each time the reference counter becomes equal to zero, the allocated space is added to the list of "available".
  • For the next distribution, the front-most memory block is used, which can fit the size.
  • Cups of previously used memory will be used again to be as possible.

Is the "available list" sorted by address or address size?

Will live objects move for better compaction?

+4
source share
2

Swift, , swift:: swift_allocObject - , , . SWIFT_RT_ENTRY_IMPL(swift_allocObject), swift::swift_slowAlloc, ... malloc() C. , Swift , malloc().

malloc() C (libc). Apple libc . malloc() /gen/malloc.c. , , .

" " ?

malloc, , , .

1. , , "".

, . , "" . , Swift, .

2.. , .

. . , , " ". ( ):

  • : , . , , 12 , 6 , 14 , 19 , 11 13 . 12 13 .

  • : , , , , , , . , , 12 14 .

  • . . , , , . , , 12 19 , 7 .

. libc , . , .

+5

Alexanders , , . , malloc . , . , . , , - . .

, , Apple , c-, . , c-. c, . , , , syscall . , c- , , OpenGL SQLite. / , c- , , . Swifts, . Swifts, Swift 4 . , # ++ , c.

0

Source: https://habr.com/ru/post/1659976/


All Articles