2 ms·
Not much memory usage is optional: in practice most applications need a given amount of memory to do what the user is asking them to do, and so the amount of sa
by rcxdude 3y ago
Not much memory usage is optional: in practice most applications need a given amount of memory to do what the user is asking them to do, and so the amount of savings that could be realised by fully implementing this is not likely to be large. The best you could hope for is the application going 'no, you can't do that' as opposed to stopping completely, which in the age of autosaving is not really much difference in practice.
There are already interfaces which can do some of what you are talking about: the most common is memory mapping backed by a file, swap, or filesystem caching. This is the most common form of 'optional' memory usage, and it's generally managed by the kernel. A lot of the kind of thing you are talking about can be mapped onto this abstraction. For cases where backing by a file doesn't make sense (e.g. it's cheaper to regenerate the cached data than to read it back from disk), if you are using a mmap-like interface, you can generally mark pages as 'don't need', which means they may be freed by the kernel if there is memory pressure, but won't be wiped immediately. Again the main issue is the use-cases where this represents a significant percentage of memory usage are pretty slim.