Kotlin-native: Add Stack Memory Access

Created on 2 Dec 2017  路  5Comments  路  Source: JetBrains/kotlin-native

Need clarification on memory access in Kotlin Native. Is memory access only available for the heap? If that is the case then stack memory access is missing.

Most helpful comment

Given the current situation with the Kotlin Native documentation there is no separate documentation covering memory management (eg MEMORY_MANAGEMENT.md). Would be extremely helpful to have a separate document that includes the following:

  • How does Kotlin Native differ from Kotlin JVM with memory management
  • Explanation on how stack memory is handled
  • Accessing/manipulating heap memory
  • Handling pointers
  • How reference counting works in Kotlin Native
  • Considerations to keep in mind with C/Python interop when it comes to managing memory

All 5 comments

It's not like that. Kotlin/Native is relatively high level language, and as such memory management doesn't explicitly specify where particular value is stored. For example, in code like

fun foo(arg: Int) {
  val tmp = arg + 1
  return tmp
}

both arg and tmp are stored on stack only, and no heap allocations take place. However, in general, it's up to compiler and runtime to decided, where to store data, as long, as it matches language contracts.

Given the current situation with the Kotlin Native documentation there is no separate documentation covering memory management (eg MEMORY_MANAGEMENT.md). Would be extremely helpful to have a separate document that includes the following:

  • How does Kotlin Native differ from Kotlin JVM with memory management
  • Explanation on how stack memory is handled
  • Accessing/manipulating heap memory
  • Handling pointers
  • How reference counting works in Kotlin Native
  • Considerations to keep in mind with C/Python interop when it comes to managing memory

We will try to improve situation in that regard, hopefully in v0.6 timeframe.

Obviously this is forgotten... such a documentation is really necessary; hopefully it can be finish in v0.8...

Please, don't forget about it, that's really important. A smart enough compiler should be able to decide which objects go to the heap and which can stay in the stack; that would be awesome and it wouldn't need any changes in the actual language.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonnyzzz picture jonnyzzz  路  4Comments

alastaircoote picture alastaircoote  路  3Comments

brettwillis picture brettwillis  路  4Comments

barsan-md picture barsan-md  路  4Comments

antanas-arvasevicius picture antanas-arvasevicius  路  4Comments