Skip to main content
28 events
when toggle format what by license comment
Aug 5, 2018 at 23:16 comment added user77406 clock() would be much shorter than srand();rand()
Apr 13, 2017 at 12:39 history edited CommunityBot
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
S Feb 22, 2017 at 12:41 history suggested MikeW CC BY-SA 3.0
spelling correction
Feb 22, 2017 at 11:41 review Suggested edits
S Feb 22, 2017 at 12:41
Feb 20, 2017 at 22:58 comment added Riley @ThomasWeller In the verification? Because my submission is just the function. int main(){f();} is there to call f(). In other words, an example of usage.
Feb 20, 2017 at 22:56 comment added Thomas Weller Why does the main method not count towards the bytes?
Feb 20, 2017 at 14:52 comment added GeirGrusom @AndrewSavinykh you can almost get the same thing with GlobalAddAtom in Windows. Also CreateFileMapping. But GlobalAddAtom isn't unrecoverable, and neither is CreateFileMapping so I guess they don't really count.
Feb 20, 2017 at 13:06 history edited Riley CC BY-SA 3.0
added 139 characters in body
Feb 19, 2017 at 19:37 history edited Riley CC BY-SA 3.0
added 462 characters in body
Feb 19, 2017 at 19:30 comment added Riley @Dennis The question says: "memory that the program allocates but looses the ability to access before it can deallocate ...". The program still has the key so it could deallocate. I'll add it, but keep the rand() one because this is borderline.
Feb 19, 2017 at 19:23 comment added Dennis But that's a full program. How would we recover &k?
Feb 19, 2017 at 19:23 comment added Riley @Dennis After the shmget call we still know what &k is so we still have the key.
Feb 19, 2017 at 19:04 comment added Dennis Right, I should have tested it more than once. main(k){shmget(&k,1,512);} should work instead of the rand() approach.
Feb 19, 2017 at 18:59 history edited Riley CC BY-SA 3.0
deleted 371 characters in body
Feb 19, 2017 at 18:52 comment added Riley @Dennis For shmget(k,1);, that doesn't always work for me. Without the third argument of 512 (which is IPC_CREAT) it doesn't always create the new segment.
Feb 19, 2017 at 18:47 comment added Riley @Dennis If the function modifies it's first argument then k will also change to that. I think that is good enough to loose the key. Thanks!
Feb 19, 2017 at 18:38 comment added Dennis But int k has the same problem, assuming it is one. tio.run/nexus/… Btw, shmget(k,1); seems to work just fine.
Feb 19, 2017 at 18:27 comment added Riley @Dennis That depends on how strict we are about loosing access. k will often be set to the first argument of the function called before f(). That means that there is a good chance we can figure out what k originally was.
Feb 19, 2017 at 17:44 comment added Dennis Would f(k){shmget(k,1,512);} work?
Feb 19, 2017 at 16:26 comment added user1643723 @AndrewSavinykh there are Linux APIs, that were considered OK at the time, but became obsolete with creation of better alternatives and saner development practices. Unlike in Windows, there is no central entity to forcibly declare stuff deprecated, everyone is free to keep using it, even if better alternatives exist. File locks are supplanted by file leases, but some people don't even know those exist; shared memory got replaced by tmpfs, but many still use it by inertia. On the bright side, there is no Vista-like breakage-feasts :)
Feb 19, 2017 at 14:24 comment added kasperd I like how you use the word problem to describe the scenario where the program leaks less memory than intended.
Feb 18, 2017 at 23:31 comment added Riley @Dennis That's why I didn't post a TIO link. I didn't know if it was protected or not.
Feb 18, 2017 at 23:30 comment added Dennis Thank you for posting this. I just protected TIO against shared memory leaks.
Feb 18, 2017 at 22:50 history edited Riley CC BY-SA 3.0
added 1297 characters in body
Feb 18, 2017 at 22:27 comment added Riley @AndrewSavinykh Shared memory basically becomes a resource that the OS can give to other processes. It is similar to a file that lives in RAM and any process that knows the name (key) has access to it until it is deleted. Imagine a process that calculates a number and stores it in memory and exits before the process that reads the data connects to the shared memory. In this case, if the OS frees the memory then the second process can't get it.
Feb 18, 2017 at 22:07 comment added tbodt @AndrewSavinykh Theoretically, the shmid could have been stored in a file and a program could attach to it in the future. This is how unix shared memory works...
Feb 18, 2017 at 21:44 comment added Andrew Savinykh Why is linux not freeing memory when process exits and nothing else is using the memory? I'm sure this scenario is not possible on windows, if there are no handles to shared memory it will get freed, and all the handles are released when process shuts down
Feb 18, 2017 at 19:04 history answered Riley CC BY-SA 3.0