From f5a1a5a17915c79b03b828b80b4858d7d68513d5 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 26 Feb 2022 16:21:04 -0600 Subject: [PATCH] Update: Delete socket rather than resize when array is over large. I realized that this might be more performant. If I have to resize the array because it is over large, then a resize could result in a copy of memory. At this point in the program, the data is irrelevant. I suspect deleting the array will perform better than resizing the array to a smaller size. --- level_3/controller/c/control/private-control.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/level_3/controller/c/control/private-control.c b/level_3/controller/c/control/private-control.c index ee1f0a6..dee5356 100644 --- a/level_3/controller/c/control/private-control.c +++ b/level_3/controller/c/control/private-control.c @@ -135,8 +135,10 @@ extern "C" { f_socket_disconnect(&client, f_socket_close_fast_e); + // Resize memory when the allocated size is greate than the maximum preferred size. + // Resizing could potentially copy memory to a new address, so it is assumed to be cheaper to just delete the memory entirely. if (control->input.size > controller_control_default_socket_buffer_d) { - status = f_string_dynamic_resize(controller_control_default_socket_buffer_d, &control->input); + status = f_string_dynamic_resize(0, &control->input); if (F_status_is_error(status)) { controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_string_dynamic_resize", F_true); @@ -146,7 +148,7 @@ extern "C" { } if (control->output.size > controller_control_default_socket_buffer_d) { - status = f_string_dynamic_resize(controller_control_default_socket_buffer_d, &control->output); + status = f_string_dynamic_resize(0, &control->output); if (F_status_is_error(status)) { controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_string_dynamic_resize", F_true); -- 1.8.3.1