Timeline for How to fill 90% of the free memory?
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 25, 2016 at 8:46 | history | edited | heemayl | CC BY-SA 3.0 | added 8 characters in body |
| Nov 8, 2013 at 16:43 | comment | added | Leo | @Sebastian: calloc will run into the same problem IIRC. All the memory will just point to the same read-only zeroed page. It won't actually get allocated until you try to write to it (which won't work since it is read-only). The only way of being really sure that I know is to do a memset of the whole buffer. See the following answer for more info stackoverflow.com/a/2688522/713554 | |
| Nov 8, 2013 at 16:17 | comment | added | user50941 | Here is a C program that mallocs and does mlock. github.com/Damienkatz/memhog | |
| Nov 8, 2013 at 15:32 | comment | added | Sebastian | @bjarkef then just use calloc. | |
| Nov 8, 2013 at 14:32 | comment | added | Bjarke Freund-Hansen | You probably have to actually write to the memory, the kernel might just overcommit if you only malloc it. If configured to, e.g. Linux will let malloc return successfully without actually having the memory free, and only actually allocate the memory when it is being written to. See win.tue.nl/~aeb/linux/lk/lk-9.html | |
| Nov 8, 2013 at 13:44 | comment | added | Sebastian | Some inspiration for the code. Furthermore, I think you don't need to unlock/free the memory. The OS is going to do that for you when your process has ended. | |
| Nov 8, 2013 at 13:34 | comment | added | Anthony | I concur with @siri; however, it depends on which variant UNIX you are using. | |
| Nov 8, 2013 at 13:31 | comment | added | Sirish Kumar Bethala | Long time back I had to test similar use case. I observed that until you write something to that memory it will not be actually allocated(i.e. until page fault happens) . I am not sure whether mlock() take cares of that. | |
| Nov 8, 2013 at 12:55 | review | First posts | |||
| Nov 8, 2013 at 13:02 | |||||
| Nov 8, 2013 at 12:36 | history | answered | Chris | CC BY-SA 3.0 |