5 ms·
Damn, it took me years to accept that dropping C-style or C++-style explicit memory management in favor of garbage collection was an overall improvement. And no
by bnegreve 3y ago
Damn, it took me years to accept that dropping C-style or C++-style explicit memory management in favor of garbage collection was an overall improvement. And now we have to reuse and mutate objects instead of creating new ones because of it.
- sroussey 3y agoI can see the need for memory management for a game. There are other things, also graphics related like map points or point clouds. You are more likely to a struct of arrays than an array of structs/objects as well. Very handy in C but also JS. I suppose you can use a sliding window object (or “fly” object) that pretends to be the object when the data is really split across various arrays, just don’t actually loop over them. ;) I bet someone has done a library for something this way and used proxies.
- nitwit005 3y agoThe React style forces a lot more object creation and copying then you're probably imagining. If you want to update an array, you generally have to make a new array, and copy over all the data except for your mutation: https://react.dev/learn/updating-arrays-in-state https://react.dev/learn/updating-arrays-in-state If you, for example, hold your voxel level data in a big array, that means copying that data every time the level is modified.
- shmde 3y ago"The React style forces a lot more object creation and copying then you're probably imagining." Its not react style its literally the core of how react works(immutablity). To rerender a component you need the new state to point towards a new reference to an object/array (hence the copying data to a new array) because JS compares objects/arrays through reference and not value. Not exactly react's fault but how JS works.
- nitwit005 3y agoI said "react style" because they are not using React in a conventional way: https://github.com/kevzettler/react-regl https://github.com/kevzettler/react-regl