From: Kevin Day Date: Sat, 26 Feb 2022 22:21:04 +0000 (-0600) Subject: Update: Delete socket rather than resize when array is over large. X-Git-Tag: 0.5.8~3 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=f5a1a5a17915c79b03b828b80b4858d7d68513d5;p=fll 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. --- 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);