3 ms·
As I remember, Cell only allows moving/copying data from/to cell so if you have a 128-byte object inside do you have to copy it to modify? Or this can be optimi
by codedokode 1y ago
As I remember, Cell only allows moving/copying data from/to cell so if you have a 128-byte object inside do you have to copy it to modify? Or this can be optimized?
- kbolino 1y agoYes, that's how Cell works. If you want to work with the data in place, you need a RefCell instead.
- codedokode 1y agoBut it is expensive, because it does run-time checks? Or they are optimized out?
- Measter 1y agoRefCell does do runtime checks, but the cost is checking the counter, a conditional branch, then incrementing/decrementing the counter twice. Because the counter is non-atomic and non-volatile the optimiser can sometimes optimise out the actual modification of the counter. It's not free, but it's not also not a huge expense.