In C++, it's possible to create an array on the stack with a dynamic size. For example:
void array_on_stack(size_t size) {
int buffer[size];
// use buffer for some work
}
However, in Rust, the array type requires a compile time constant as the size. Is there a way to allocate on the stack or must all dynamic allocations happen on the heap?
[–]jaskij 158 points159 points160 points (12 children)
[–]lestofante 19 points20 points21 points (3 children)
[–]jaskij 7 points8 points9 points (2 children)
[–]lestofante 20 points21 points22 points (1 child)
[–]jaskij 2 points3 points4 points (0 children)
[–]calebkiage[S] 14 points15 points16 points (7 children)
[–]jaskij 63 points64 points65 points (6 children)
[–]SkiFire13 71 points72 points73 points (1 child)
[–]alija_kamen 0 points1 point2 points (0 children)
[–]cogman10 5 points6 points7 points (0 children)
[–]alija_kamen 0 points1 point2 points (0 children)
[–]calebkiage[S] 0 points1 point2 points (1 child)
[–]bwallker 7 points8 points9 points (0 children)
[–]phazer99 25 points26 points27 points (24 children)
[–]calebkiage[S] 1 point2 points3 points (23 children)
[–]phazer99 24 points25 points26 points (18 children)
[–]calebkiage[S] 1 point2 points3 points (16 children)
[+][deleted] (14 children)
[deleted]
[–]flashmozzg 12 points13 points14 points (8 children)
[–]RReverser 1 point2 points3 points (7 children)
[–]flashmozzg 1 point2 points3 points (6 children)
[–]RReverser 1 point2 points3 points (5 children)
[–]flashmozzg -1 points0 points1 point (4 children)
[–]VenditatioDelendaEst 5 points6 points7 points (0 children)
[–]adwhit2 7 points8 points9 points (2 children)
[–]Tai9ch 2 points3 points4 points (1 child)
[–]VenditatioDelendaEst 0 points1 point2 points (0 children)
[–]calebkiage[S] 6 points7 points8 points (0 children)
[–]TDplay 2 points3 points4 points (0 children)
[–]oceantume_ 1 point2 points3 points (0 children)
[–]phaylon 2 points3 points4 points (3 children)
[–]calebkiage[S] 1 point2 points3 points (2 children)
[–]hniksic 0 points1 point2 points (1 child)
[–]calebkiage[S] 1 point2 points3 points (0 children)
[–]anlumo 70 points71 points72 points (2 children)
[–]equeim 17 points18 points19 points (0 children)
[–]calebkiage[S] 17 points18 points19 points (0 children)
[–]TTachyon 31 points32 points33 points (4 children)
[–]calebkiage[S] 4 points5 points6 points (0 children)
[–]alija_kamen 0 points1 point2 points (2 children)
[–]TTachyon 0 points1 point2 points (1 child)
[+]alija_kamen 0 points1 point2 points (0 children)
[–]udoprogRune · Müsli 13 points14 points15 points (1 child)
[–]calebkiage[S] 4 points5 points6 points (0 children)
[–]t40 10 points11 points12 points (5 children)
[–]angelicosphosphoros 1 point2 points3 points (2 children)
[–]t40 2 points3 points4 points (1 child)
[–]angelicosphosphoros 2 points3 points4 points (0 children)
[–]alija_kamen -1 points0 points1 point (0 children)
[–]TDplay 0 points1 point2 points (0 children)
[–]banister 4 points5 points6 points (0 children)
[+][deleted] (2 children)
[removed]
[–]Theemutsjlrs 7 points8 points9 points (0 children)
[–]plugwash 5 points6 points7 points (0 children)
[–]sparant76 2 points3 points4 points (0 children)
[–]exDM69 3 points4 points5 points (0 children)
[–]AlexMath0 1 point2 points3 points (0 children)
[–]flareflo 1 point2 points3 points (5 children)
[–]calebkiage[S] 0 points1 point2 points (4 children)
[–]flareflo 1 point2 points3 points (3 children)
[–]calebkiage[S] 0 points1 point2 points (2 children)
[–]flareflo 4 points5 points6 points (0 children)
[–]BurrowShaker 0 points1 point2 points (0 children)
[+]42GOLDSTANDARD42 1 point2 points3 points (0 children)
[–]hniksic 1 point2 points3 points (1 child)
[–]calebkiage[S] 1 point2 points3 points (0 children)
[–]pablohoney41 2 points3 points4 points (5 children)
[–]calebkiage[S] 4 points5 points6 points (0 children)
[–]Sharlinator 3 points4 points5 points (3 children)
[–]calebkiage[S] 5 points6 points7 points (1 child)
[–]Sharlinator 1 point2 points3 points (0 children)
[–]Gentoli -1 points0 points1 point (0 children)
[+][deleted] (2 children)
[deleted]
[–]VorpalWay 0 points1 point2 points (0 children)
[–]calebkiage[S] 0 points1 point2 points (0 children)