|
It's a whole ton of daemons and tools. This goes back to 1990, but it has changed a few times. Apparently it's either never run in a low memory environment, or something eventually finishes with the memory it's using, so the next thing can have a go. Or we just tell the customer to buy more RAM. Yeah, this is software we sell. Some of your IT departments might be using it for backups. I guess I should ask why this is done this way.
|
# ? May 9, 2013 19:45 |
|
|
# ? May 16, 2024 19:04 |
|
nielsm posted:But you know, it'd be great if it could, like, just die all on its own if something like that happened, right? What a good idea, why lets just make every library function that can't malloc something just abort() the program! Absolutely nothing could possibly go wrong with this approach!
|
# ? May 9, 2013 19:48 |
|
Munkeymon posted:It's OK - it only keeps going until someone notices the process isn't responding and kills it and they probably have a script for that. Yeah I found some memory problems... wrote a cron job to restart the process; fixed.
|
# ? May 9, 2013 19:52 |
|
hobbesmaster posted:What a good idea, why lets just make every library function that can't malloc something just abort() the program! Absolutely nothing could possibly go wrong with this approach! zergstain posted:I guess I should ask why this is done this way.
|
# ? May 9, 2013 19:52 |
|
Most programs in most situations are just going to die if memory allocation fails. If you've got global caches, then your malloc wrapper can try to clear those and try again, but otherwise, sleeping and hoping that the memory crunch was temporary is pretty much all you can do at that point. If it wasn't temporary, then your failure mode goes from (a) crashing and usually bringing up bizarre messages to the user to (b) hanging and, hopefully, leaving the system responsive enough that the user can just kill the program. I mean, yes, it is possible to write code that handles a failure in memory allocation gracefully. Usually what's actually written is code that (1) leaks a ton of stuff, (2) leaves the program in a completely inconsistent internal state, and then (3) fails ungracefully in the end anyway because all of the sudden random untested code paths are being taken.
|
# ? May 9, 2013 19:53 |
|
JawnV6 posted:The sarcasm doesn't hit as hard when they're using xmalloc. You know, specifically meant to do exactly the thing you're mocking. (but they're not even having their xmalloc implementation do that, they're just spinning instead!) rjmccall posted:Most programs in most situations are just going to die if memory allocation fails. If you've got global caches, then your malloc wrapper can try to clear those and try again, but otherwise, sleeping and hoping that the memory crunch was temporary is pretty much all you can do at that point. If it wasn't temporary, then your failure mode goes from (a) crashing and usually bringing up bizarre messages to the user to (b) hanging and, hopefully, leaving the system responsive enough that the user can just kill the program. You can do something graceful with most (almost?) all failed malloc calls.
|
# ? May 9, 2013 19:57 |
|
Zaphod42 posted:Yeah I found some memory problems... wrote a cron job to restart the process; fixed. Rails did this for about three years
|
# ? May 9, 2013 19:58 |
|
hobbesmaster posted:You can do something graceful with most (almost?) all failed malloc calls. Another coding horror found.
|
# ? May 9, 2013 20:16 |
|
floWenoL posted:Another coding horror found. How in the world do you think those custom "Oh no the program crashed!" handlers show up?
|
# ? May 9, 2013 20:19 |
|
SIGCHLD
|
# ? May 9, 2013 20:33 |
|
hobbesmaster posted:How in the world do you think those custom "Oh no the program crashed!" handlers show up? My money is on fairies.
|
# ? May 9, 2013 20:33 |
|
hobbesmaster posted:How in the world do you think those custom "Oh no the program crashed!" handlers show up? I'm not sure what you're referring to, but code paths to handle failed malloc calls are rarely exercised and frequently lead to your program being in a weird state. Since failed malloc calls are rarely actually related to low-memory conditions (in desktop applications) it seems preferable to crash so that the problem can be found and fixed.
|
# ? May 9, 2013 20:37 |
|
zergstain posted:After 4 months of being here (I'm on an 8 month co-op (that thing I said about only having 3 semesters left? I'm expecting to finish in April 2015)), I think I have something worthy of this thread. I hope you fixed the bit where you're using ok as a variable name, because this just looks like do { ... } while (0);.
|
# ? May 9, 2013 21:04 |
|
hobbesmaster posted:You can do something graceful with most (almost?) all failed malloc calls. Obviously (i.e. hopefully) this belief doesn't come from experience.
|
# ? May 9, 2013 21:42 |
|
JawnV6 posted:I wouldn't chase that rabbit. I did, turns out that daemons just dying is bad, so the solution was just make it spin until it succeeds. Guy told me not to use this function, and a fun RPC exploit involving telling one of the daemons you're about to send it a list with 3 billion items. The variable is still called ok. Don't see how it looks like do { } while(0)
|
# ? May 9, 2013 21:47 |
|
You guys have systems that allow you to hotswap more ram in?
|
# ? May 9, 2013 21:53 |
|
zergstain posted:The variable is still called ok. Don't see how it looks like The block still gets executed. And if that isn't how its used, then while(true) with break statements would work. E: Oh the variable was called ok, I thought you were saying "the variable is used, okay?". "ok" is a terrible var name. Zaphod42 fucked around with this message at 23:01 on May 9, 2013 |
# ? May 9, 2013 21:55 |
|
zergstain posted:The variable is still called ok. Don't see how it looks like A variable named ok looks like a constant whose boolean value is true. A statement like if(ok) looks like if(1), while(ok != TRUE) looks like while(0) and ok = FALSE; just looks like nonsense. I prefer isOK, isValid or retcode or something along those lines.
|
# ? May 9, 2013 22:36 |
|
qntm posted:A variable named ok looks like a constant whose boolean value is true. In C? That's far from universal. And it sounds like a bad idea anyway: naming a constant in the global (i.e. only) namespace after a common word that follows the convention for names of functions and local variables.
|
# ? May 9, 2013 22:49 |
|
Speaking of out-of-memory problems, how does various languages handle running out of stack space?
|
# ? May 9, 2013 23:15 |
|
I don't think I've ever seen 'ok' used as a true constant, while I have seen it used as a variable in exactly that way a lot of times.
|
# ? May 9, 2013 23:16 |
|
Plorkyeran posted:I don't think I've ever seen 'ok' used as a true constant, while I have seen it used as a variable in exactly that way a lot of times. In scala I will occasionally use ✓ (unicode tick) as a value for true.
|
# ? May 9, 2013 23:19 |
|
If you really want to you can read any "ok" or "success" type variable as a constant. Even something more specific like "fileReadSuccess" could be read as a constant enum value instead of a variable.
|
# ? May 9, 2013 23:37 |
|
thisVariableIndicatesIfTheFileHasBeenReadFromSuccessfully
|
# ? May 9, 2013 23:41 |
|
ymgve posted:Speaking of out-of-memory problems, how does various languages handle running out of stack space? In C++ on Windows at least you can hook up a handler. It actually works decently for recovery. ("Running out of stack space" doesn't generally mean the system has no more. It's usually just the OS going "hey process wtf are you doing.")
|
# ? May 9, 2013 23:55 |
|
SQLite is one of the few codebases I've seen that handles out-of-memory conditions properly.ymgve posted:Speaking of out-of-memory problems, how does various languages handle running out of stack space? Go's stacks are linked lists of heap-allocated chunks, so it just allocates a new chunk when it runs out.
|
# ? May 10, 2013 00:04 |
Scaevolus posted:Go's stacks are linked lists of heap-allocated chunks, so it just allocates a new chunk when it runs out. So an infinite recursion takes how long to crash?
|
|
# ? May 10, 2013 00:08 |
|
Scaevolus posted:SQLite is one of the few codebases I've seen that handles out-of-memory conditions properly.
|
# ? May 10, 2013 00:10 |
|
nielsm posted:So an infinite recursion takes how long to crash? Not very long: code:
|
# ? May 10, 2013 00:27 |
|
Sang- posted:In scala I will occasionally use ✓ (unicode tick) as a value for true. I honestly can't tell if this is a serious post.
|
# ? May 10, 2013 00:30 |
|
Freakus posted:If you really want to you can read any "ok" or "success" type variable as a constant. Even something more specific like "fileReadSuccess" could be read as a constant enum value instead of a variable. Erlang IO functions return the atom 'ok' on a successful write
|
# ? May 10, 2013 00:37 |
|
Volmarias posted:I honestly can't tell if this is a serious post. mostly in joke projects, but it does (sometimes) improve readability
|
# ? May 10, 2013 00:42 |
|
hobbesmaster posted:You can do something graceful with most (almost?) all failed malloc calls. No, you cannot. If you are using malloc to respond to a malloc failure for example (don't laugh, it happens more often than you think), and that malloc call fails in turn (a double fault), there's not a lot you can do. I used to do Windows kernel-mode development a long time ago, and you had to be extremely conservative about... everything. Regarding memory allocation, if you needed a resource in your failure path whose allocation could possibly fail (like, a task for delayed execution of a clean-up routine at a lower interrupt level or outside of a client thread), you just allocated it up front at object creation, on the off-chance you'd need it later. That is how you account for malloc failures, and it's a pain that's totally not worth it unless the risk is high enough (e.g. crashing the machine)
|
# ? May 10, 2013 09:33 |
|
Volmarias posted:I honestly can't tell if this is a serious post.
|
# ? May 10, 2013 11:50 |
|
Rottbott posted:I grudgingly renamed my C++ function named 'MetresPerSecond˛' (which worked fine in MSVC) because it crashed XCode/Clang. I once used Δx and Δy (or similar) variable names in Java in a toy project.
|
# ? May 10, 2013 12:48 |
|
Volmarias posted:I honestly can't tell if this is a serious post. Please enjoy the unicode operators in ScalaZ.
|
# ? May 10, 2013 13:21 |
|
"Enterprise" APIs are always funny, in a tragic way of course, and by being "Enterprise" means nobody wants to fix anything. Return values are an obvious point of calamity, Microsoft also ventured this road with DirectX and wrappers for return values: SUCCEEDED and FAILED. Here's what happens otherwise:code:
|
# ? May 10, 2013 14:48 |
|
How do I linked list?code:
tail is initialized to NULL, and only gets assigned at the point you see, asof is a parameter to the function, as well as headp. xcalloc() is of course like the xmalloc() I mentioned (we also have xstrdup()). This code uses 4 space indents while the surrounding code uses tabs. The function is supposed to build a linked list of times and paths.
|
# ? May 10, 2013 15:28 |
|
do Hardware Horrors count? It's Ouya so I'm going to assume yes....JazzFlight posted:This is loving amazing.
|
# ? May 10, 2013 17:36 |
|
|
# ? May 16, 2024 19:04 |
|
Civil Twilight posted:Please enjoy the unicode operators in ScalaZ. Looks sort of like some people's Haskell when they use μ α instead of m a in type signatures.
|
# ? May 10, 2013 17:38 |