Context receivers seem to be extremely useful when...
# kotlin-native
e
Context receivers seem to be extremely useful when dealing with transformations that should be done under a
memscoped
block.
Copy code
context (NativePlacement)
internal fun LPWSTR.toLatin1Buffer(): LPSTR {
  val latin1BufferSize = WideCharToMultiByte(28591u /* ISO-8859-1 */, 0u, this@toLatin1Buffer, 0, null, 0, null, null)
  val latin1buffer = allocArray<CHARVar>(latin1BufferSize)
  WideCharToMultiByte(28591u /* ISO-8859-1 */, 0u, this@toLatin1Buffer, 0, latin1buffer, 0, null, null)
  return latin1buffer
}
o
IMO, yes and no, because you will always think, that you can easily/safely move
NativePlacement
to context receiver and then, in this case you can accidentally be trapped in a situation when you create single
MemScope
block for whole application - and so it will be never actually cleared So, that' a good use case, but for me it's dangerous - but may be Im overreacting 🙂