r/programminghorror • u/Liam_Mercier • Feb 08 '26
c++ Saving data to dynamic object files
Some people persist data in JSON, but why do that when we have perfectly good object files? All you have to do is recompile the file when you want to save your data!
237
Upvotes
3
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Feb 09 '26
A hard limit of 40 items, eh? That should meet the needs of almost everyone.
56
u/MooseBoys [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Feb 08 '26
int res = system("g++ -shared -fPIC inv_dll.cpp -o inventory.so");Aw that's no fun. You gotta construct the dll in-place!
90
u/ironykarl Feb 08 '26
Is it a good idea? Not really, no.
Is it a fun idea? I kind of think so
30
u/BroBroMate Feb 08 '26
So this is where Python's pickle module learned its bad habits of "let's serialize things in an executable format" from!
1
u/HandyProduceHaver Feb 11 '26
I happen to have an item called itemName"}\nscaryLibrary.deleteImportantFile()
4
u/ArnaktFen Feb 08 '26
This is hilarious. It's totally worth doing just to prove it can be done.
2
u/LeviLovie Feb 08 '26
Why don’t just serialize the inventory into a DLL byte for byte without a compiler then? :D
2
u/NIdavellir22 Feb 08 '26
What the hell
4
u/Lumpy_Marketing_6735 Feb 08 '26
Am I having a stroke what is this, Im not sure what the hell is happening but I think (at least in C++) this is what Vector is meant to do.