2 ms·
Newbie question if someone doesn't mind. This seems to make it easier to do stuff without allocating heap memory. How large is the stack? Can I do complex thi
by Waterluvian 6y ago
Newbie question if someone doesn't mind.
This seems to make it easier to do stuff without allocating heap memory.
How large is the stack? Can I do complex things with only the stack?
- zucker42 6y agoThis is an OS question, not a Rust question. Try typing ulimit -s if you are on a Unix-style system to get the maximum stack size (on my system it's in KB). And yes, you can do many things using the stack; it's just not as flexible. But const generics are most useful for increasing the efficiency of certain code while keeping it reusable.
- grdvnl 6y agoI am curious. Why do you think it helps it doing things on the stack. For me, I understand this to provide more generic type level checks on the size/shape of values. Perhaps, I am oversimplifying this?
- lasagnaphil 6y agoBasically, the const-generics feature gives the programmer the ability to create fixed-size custom types that doesn't allocate on the heap. For example, with current Rust you can't make your own generic fixed-size hashmap (as in FixedSizeHashMap<K, V, N: uint>, where N is the maximum number of keys you can use) that doesn't use the heap, since you can't use size-parameterized arrays in structs. Although this isn't a big deal for most general programming purposes, it still matters a lot in domains like embedded/HFT/gamedev/simulation where minimal latency is incredibly important. It's also important when you want to create any sort of linear algebra library (such as Eigen). For me const-generics is an important dealbreaker when choosing between Rust and C++ (where C++ already had the ability to do this for decades).