From 651c020b87175abe5ec848306884037f986fa0b3 Mon Sep 17 00:00:00 2001 From: Elias Bachaalany Date: Tue, 2 Dec 2025 15:53:37 -0800 Subject: [PATCH] Use stack-allocated ctx_t array instead of heap allocation - Initialize ctxs[i] directly with aggregate initialization - Pass address of stack object to CreateThread - Use dot notation instead of arrow for member access - Remove delete calls since no heap allocation Co-authored-by: Maurice Heumann --- src/samples/test-sample/test.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/samples/test-sample/test.cpp b/src/samples/test-sample/test.cpp index 641b46a7..ef7bbdd9 100644 --- a/src/samples/test-sample/test.cpp +++ b/src/samples/test-sample/test.cpp @@ -111,8 +111,8 @@ namespace for (int i = 0; i < thread_count; i++) { - ctx_t* ctx = ctxs[i] = new ctx_t{5 * (i + 1), i - 2}; - threads[i] = CreateThread(nullptr, 0, thread_proc, ctx, 0, nullptr); + ctxs[i] = {5 * (i + 1), 0}; + threads[i] = CreateThread(nullptr, 0, thread_proc, &ctxs[i], 0, nullptr); if (!threads[i]) { return false; @@ -124,12 +124,11 @@ namespace const int expected_results[thread_count] = {5, 10, 15, 20, 25}; for (int i = 0; i < thread_count; i++) { - if (ctxs[i]->result != expected_results[i]) + if (ctxs[i].result != expected_results[i]) { return false; } CloseHandle(threads[i]); - delete ctxs[i]; } return true;