Why do I need to copy data out of memory mapped files to avoid seg faults.
This defeats the purpose of memory mapped files.
Shouldn't the GC be able to manage it if I keep a pointer into it.
I am closing them because the OS has a limit in how many it can open, either way the memory is still there isn't it ?
September 01, 2023 Keeping data from memory mapped files | ||||
---|---|---|---|---|
| ||||
September 01, 2023 Re: Keeping data from memory mapped files | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexibu | On Fri, Sep 01, 2023 at 03:53:42AM +0000, Alexibu via Digitalmars-d-learn wrote: > Why do I need to copy data out of memory mapped files to avoid seg faults. > This defeats the purpose of memory mapped files. > Shouldn't the GC be able to manage it if I keep a pointer into it. The GC does not manage memory-mapped files. That's the job of the OS. > I am closing them because the OS has a limit in how many it can open, either way the memory is still there isn't it ? No, once you close it, the OS will remove the mapping. So when you try to access that address, it will segfault. This has nothing to do with the GC, the page tables that map the memory addresses to the file are managed by the OS. By closing it you're basically telling the OS "I don't need the mapping anymore", so it removes the mapping from your page tables and that address no longer exists in your process' address space. So the next time you try to access it, you will get a segfault. T -- Heuristics are bug-ridden by definition. If they didn't have bugs, they'd be algorithms. |
Copyright © 1999-2021 by the D Language Foundation