resource usage concerns
resource usage concerns
Posted Mar 20, 2025 22:39 UTC (Thu) by wahern (subscriber, #37304)In reply to: resource usage concerns by tialaramex
Parent article: Oxidizing Ubuntu: adopting Rust utilities by default
The stack does shrink. Example program:
#include <stdio.h> #include <stdint.h> #include <string.h> __attribute__((noinline)) static void showfp(unsigned n, intptr_t otop) { intptr_t top = (intptr_t)__builtin_stack_address(); printf("n:%u off:%td\n", n, (otop > top)? otop - top : top - otop); } int main(void) { unsigned n = 0; intptr_t top = (intptr_t)__builtin_stack_address(); while (1 == scanf("%u", &n)) { char buf[n]; memset_s(buf, n, 0, n); showfp(n, top); } return 0; }
For `echo 200 100 5 | ./a.out` I get:
n:200 off:272 n:100 off:176 n:5 off:80
As the size of successive stack allocations decrease, so does the frame size.
Posted Mar 21, 2025 13:39 UTC (Fri)
by tialaramex (subscriber, #21167)
[Link] (2 responses)
I assume, since your example is a VLA that if you write a conventional C89 array or any other type it is not in fact creating and destroying the allocation.
Posted Mar 21, 2025 22:42 UTC (Fri)
by wahern (subscriber, #37304)
[Link] (1 responses)
For posterity: I've been using gcc version 14.2.0 (MacPorts gcc14 14.2.0_3+stdlib_flag) on an ARM M1 with these test cases. (__builtin_stack_address was too convenient, but not supported by the installed Apple clang toolchain, though it seems it is supported by the latest upstream clang release.)
Posted Mar 21, 2025 23:29 UTC (Fri)
by tialaramex (subscriber, #21167)
[Link]
So that's on me. It did cause me to go find out what the current status is of (formally supported rather than as a hack) VLA-like Rust objects (ie a runtime sized object lives on the stack) and seems like they're not close.
resource usage concerns
resource usage concerns
resource usage concerns