Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local str = fs.read(path):getdata()
nice, this will suffice.
...don't see myself ever using this. Every time I've ever used a file in lua, I've either read the whole thing...
i have used it a lot, and already have plans for it. although reading parts would be more important than writing parts.
it's not really needed, but without would make small random access to very large files rather slow and complicated. pathfinding data from drones for example grows fast and can easily grow above multiple hundred MB. not an every-day usage-case ofc.
ramdisks
ye, thought about caching stuff too. but it really is just frosting on the cake.
The device should use coroutines to slowly read the file in chunks, then piece the chunks together and send the whole thing at once. If you want a big file (or a big chunk of a file), it will work without lagging the server but will take a while. There should also be a maximum file size.
exactly what i mean.
How?
seems xpcall in minetest can somewhat handle OoMs - when xpcall runs out of memory it will not call the error-callback, but just return {false,"out of memory"}. far from a system that can actually limit/determine memory of a single (computer's) coroutine reliably, which seems to be a real pain to be done from inside lua.
so for now it should work if we change computer.lua's
local cr = coroutine.create(function() xpcall(bootstrap,error_handler) end)
to
local cr = coroutine.create(function() return xpcall(bootstrap,error_handler) end)
and check for the "out of memory" message in the crashed coroutine's return-value.
not a final solution, but could be a first step to stop players from crashing the server with memleaks.
sadly this would not enable per-computer-limits, but would ofc just trigger when minetest's global lua mem-limits get reached by a computer's coroutine.
meaning a computer could just fill 31.9GB of 32GB RAM and then wait for minetest itself to go OOM and crash without this measure doing anything.
i was thinking about using collectgarbage,__method and __gc_methods and so on to fiddle something up, maybe to calculate memory-size of userspace-table (ugh, would mean counting whole userspace basically everytime anything is done). but even if so we still need to make sure all of the queues/storages the player may access in any matter, are confined by max-limits. current example: make the event-queue(s) reject/pushover in case of too many queued events, so players cannot put a peripheral in a state where it will blow up minetest with a billion-events-queue or smth. same for console_histories (gets clipped to 4096 chars), and probably other stuff.
btw: with the proto, what happens to pending request when the requesting device has crashed before retrieving results? or was mined away or whatever.