6 ms·
How to Make Rust Leak Memory (Also: How to Make It Stop)
- mwcampbell 4y agoThis is super tangential, but does anyone else find it sad that operating systems receive keys from USB keyboards using polling rather than interrupts? Wouldn't comprehensive use of interrupts rather than polling allow the processor to move to a lower-power state? No wonder our closed smartphones are more battery-efficient than our open PCs.
- deleted 4y ago[deleted]
- TingPing 4y agoYou think polling at 500hz has a meaningful impact on your CPU?
- IshKebab 4y agoPolling at 1kHz (the usual rate) definitely would have an impact on your CPU because it would mean it can never go to sleep. Fortunately he's wrong - the CPU doesn't do the polling itself.
- Findecanor 4y agoThere is a common misconception that the host would be polling the keyboard state every time. It is actually polling to ask the device if it has a new packet to send. If the keyboard's state hasn't changed then there is no new packet and there isn't any input processing done by the CPU. The host polls because it is in control of scheduling all activity on the bus. It must be scheduled because there can be multiple devices (and multiple interfaces per device) with different characteristics on the same bus, and they must be kept from interfering with one-another.
- oconnor663 4y agoIs this done by a CPU thread, or by dedicated hardware in the USB controller? Does the controller ever interrupt the CPU?
- jai_ 4y agoIf you're interested, here's a really comprehensive video on how USB keyboards work which may answer your question: https://youtu.be/wdgULBpRoXk https://youtu.be/wdgULBpRoXk
- vlmutolo 4y agoWow, that was an absolutely incredible breakdown. Didn't expect to watch a 30min video on the USB protocol tonight. Really didn't expect to suddenly want an oscilloscope.
- SxC97 4y agoBen Eater has one of the best channels on YouTube! If you haven’t already, check out his 8 bit bread board computer series. He explains how to make a computer, completely from scratch. Coming from the software world, I found this to be absolutely fascinating!
- phibz 4y agoAny idea why Ben hasn't posted in a while?
- fleventynine 4y agoThe USB host controller does the polling in hardware. The cpu does not get involved until a key is pressed (the host controller can interrupt the cpu, telling it that new data is available).
- deleted 4y ago[deleted]
- DoctorOW 4y ago"Memory leaks are memory safe in Rust" -- https://doc.rust-lang.org/book/ch15-06-reference-cycles.html https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
- oconnor663 4y agoIn this case it seems like the leak was just "accidentally keeping references to objects that we should've stopped using", as opposed to leaking truly unreachable memory.
- Iris2645 4y ago
- phibz 4y agoI've heard this called "buffer bloat" to distinguish it from an actual memory leak.