making an editor for something and trying to figure out how to implement undo/redo, in the past I would just save the file to memory after every change and store it in a stack, but this editor the files are gonna be tens of megabytes in size
-
Show this thread
-
so instead I decided to structure the editor so that tools only ever create "commands" that change the thing you're editing, and all commands have to be reversible (individual commands can store the previous state of what they changed)
3 replies 0 retweets 27 likesShow this thread -
I guess this is an existing "design pattern" but also I still hate all "design patterns"
7 replies 0 retweets 34 likesShow this thread -
Replying to @TylerGlaiel
You can still do it your old way if you want. Just use a fast hash (like Meow), and hash blocks of the file, then store the list of hashes instead of the whole file.
2 replies 0 retweets 3 likes -
Replying to @cmuratori
the main issue is just that "saving the file" is relatively expensive here, and can't be threaded (or rather I really really dont want to deal with threading here), less so the storage (cause like even a 10mb file would "only" use up 2.5 gigs of ram for an undo stack size of 256)
2 replies 0 retweets 0 likes -
Replying to @TylerGlaiel @cmuratori
also its not that hard to ensure that my "commands" here are reversible, the actual code for executing the commands is pretty small (the entire file for that is ~70 lines of code currently). though that might not be the case if it was a more complicated thing
1 reply 0 retweets 0 likes
Yeah - I mean I'm not suggesting that there's any reason _not_ to use commands, most people do, I'm just saying your old method probably would still work just fine.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.