Open psydvl opened 2 years ago
I don't think it's expected to work in the playground or on your own device when just running the solution in a terminal.
Normally, the program that spawns your process will give you the right stdin, stdout, and stderr, which are pipes or something. To get them to be files, you can close these file descriptors and open a file. If you wanted to replicate the behavior of the evaluation environment, you could have some runner process that closes fd 0 and 1 (optionally after dup'ing them so you can still use the streams) and opens the input file obtaining fd 0 for it and the output file obtaining fd 1 for it, then forks and execs the solution.
If you also want the mapped file to be backed by huge pages, there are some additional details to get right.
It would be cool if there was a publicly available runner that did all this stuff. For now, I just have two different versions of the functions that map the file, one for local use that ends up using FD 3 or something and another for submissions.
There is an article about copying stdin to mmap with some languages https://github.com/Highload-fun/platform/wiki/How-to-use-MMAP-to-optimize-data-reading I didn't check it for nothing except go However, for golang it seems broken
https://go.dev/play/p/k38kOkm_-T1