From faee954d1a1cb453aab5216db0c059628e5733a4 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 12 Jul 2018 11:12:45 +0300 Subject: [PATCH] Better reading to buffer in example. --- samples/tetris/src/main/kotlin/Config.kt | 27 +++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/samples/tetris/src/main/kotlin/Config.kt b/samples/tetris/src/main/kotlin/Config.kt index 17280f72a3e..a25e47cc828 100644 --- a/samples/tetris/src/main/kotlin/Config.kt +++ b/samples/tetris/src/main/kotlin/Config.kt @@ -30,21 +30,18 @@ object Config { val file = fopen("config.txt", "r") if (file != null) { try { - memScoped { - val bufferLength = 2 * 1024 - val buffer = allocArray(bufferLength) - while (true) { - val nextLine = fgets(buffer, bufferLength, file)?.toKString() - if (nextLine == null || nextLine.isEmpty()) break - val records = nextLine.split('=') - if (records.size != 2) continue - val key = records[0].trim() - val value = records[1].trim() - when (key) { - "width" -> width = value.toInt() - "height" -> height = value.toInt() - "startLevel" -> startLevel = value.toInt() - } + val buffer = ByteArray(2 * 1024) + while (true) { + val nextLine = fgets(buffer.refTo(0), buffer.size, file)?.toKString() + if (nextLine == null || nextLine.isEmpty()) break + val records = nextLine.split('=') + if (records.size != 2) continue + val key = records[0].trim() + val value = records[1].trim() + when (key) { + "width" -> width = value.toInt() + "height" -> height = value.toInt() + "startLevel" -> startLevel = value.toInt() } } } finally {