Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
zergstain
Dec 15, 2005

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.

Adbot
ADBOT LOVES YOU

hobbesmaster
Jan 28, 2008

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!

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

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. :doh:

JawnV6
Jul 4, 2004

So hot ...

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!
The sarcasm doesn't hit as hard when they're using xmalloc. You know, specifically meant to do exactly the thing you're mocking.

zergstain posted:

I guess I should ask why this is done this way.
I wouldn't chase that rabbit.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
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.

hobbesmaster
Jan 28, 2008

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.

:thejoke:

(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.

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.

You can do something graceful with most (almost?) all failed malloc calls.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Zaphod42 posted:

Yeah I found some memory problems... wrote a cron job to restart the process; fixed. :doh:

Rails did this for about three years :q:

floWenoL
Oct 23, 2002

hobbesmaster posted:

You can do something graceful with most (almost?) all failed malloc calls.

Another coding horror found.

hobbesmaster
Jan 28, 2008

floWenoL posted:

Another coding horror found.

How in the world do you think those custom "Oh no the program crashed!" handlers show up?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
SIGCHLD

Slanderer
May 6, 2007

hobbesmaster posted:

How in the world do you think those custom "Oh no the program crashed!" handlers show up?

My money is on fairies.

floWenoL
Oct 23, 2002

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.

qntm
Jun 17, 2009

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.

code:
        do {
...
        } while (ok != TRUE);

I basically rewrote much of it, it's sitting in code review right now. I was told to put the original author on the review request because he needs to learn how to code better.

I hope you fixed the bit where you're using ok as a variable name, because this just looks like do { ... } while (0);.

shrughes
Oct 11, 2008

(call/cc call/cc)

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.

zergstain
Dec 15, 2005

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)

Dren
Jan 5, 2001

Pillbug
You guys have systems that allow you to hotswap more ram in?

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

zergstain posted:

The variable is still called ok. Don't see how it looks like
do {
} while(0)

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

qntm
Jun 17, 2009

zergstain posted:

The variable is still called ok. Don't see how it looks like
do {
} while(0)

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.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

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.

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
Speaking of out-of-memory problems, how does various languages handle running out of stack space?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
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.

Sang-
Nov 2, 2007

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.

Freakus
Oct 21, 2000
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.

tractor fanatic
Sep 9, 2005

Pillbug
thisVariableIndicatesIfTheFileHasBeenReadFromSuccessfully

raminasi
Jan 25, 2005

a last drink with no ice

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.")

Scaevolus
Apr 16, 2007

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.

nielsm
Jun 1, 2009



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?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Scaevolus posted:

SQLite is one of the few codebases I've seen that handles out-of-memory conditions properly.
SQLite is also notable for having over 1000 times as many lines of tests as lines of non-test code.

Rothon
Jan 4, 2012

nielsm posted:

So an infinite recursion takes how long to crash?

Not very long:

code:
~ > cat test.go
package main

func loop() {
	loop()
}

func main() {
	loop()
}
~ > time go run test.go
fatal error: out of memory (stackcacherefill)

goroutine 1 [running]:
[fp=0x7f9def007f58] runtime.malg(0x400c18)
	/usr/lib/go/src/pkg/runtime/proc.c:1451 +0xc3
[fp=0x7f9def007f60] main.loop()
	/home/sfackler/test.go:4 +0x18
[fp=0x7f9def007f68] main.loop()
	/home/sfackler/test.go:4 +0x18
[fp=0x7f9def007f70] main.loop()
	/home/sfackler/test.go:4 +0x18
[fp=0x7f9def007f78] main.loop()
	/home/sfackler/test.go:4 +0x18
[fp=0x7f9def007f80] main.loop()
	/home/sfackler/test.go:4 +0x18
[fp=0x7f9def007f88] main.loop()
	/home/sfackler/test.go:4 +0x18
[fp=0x7f9def007f90] main.main()
	/home/sfackler/test.go:8 +0x18
[fp=0x7f9def007fb8] runtime.main()
	/usr/lib/go/src/pkg/runtime/proc.c:182 +0x92
[fp=0x7f9def007fc0] runtime.goexit()
	/usr/lib/go/src/pkg/runtime/proc.c:1223

goroutine 2 [runnable]:
exit status 2
Command exited with non-zero status 1
0.56user 1.07system 0:01.66elapsed 98%CPU (0avgtext+0avgdata 3628716maxresident)k
11792inputs+0outputs (31major+911213minor)pagefaults 0swaps

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

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.

more like dICK
Feb 15, 2010

This is inevitable.

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

Sang-
Nov 2, 2007

Volmarias posted:

I honestly can't tell if this is a serious post.

mostly in joke projects, but it does (sometimes) improve readability

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

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)

Rottbott
Jul 27, 2006
DMC

Volmarias posted:

I honestly can't tell if this is a serious post.
I grudgingly renamed my C++ function named 'MetresPerSecond˛' (which worked fine in MSVC) because it crashed XCode/Clang.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

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.

Civil Twilight
Apr 2, 2011

Volmarias posted:

I honestly can't tell if this is a serious post.

Please enjoy the unicode operators in ScalaZ.

MrMoo
Sep 14, 2000

"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:
if ((retval = rsslGetChannelInfo(chnl, &chanInfo, &error)) >= RSSL_RET_SUCCESS)
...
if (processRequest(chnl, msgBuf) == RSSL_RET_SUCCESS)
...
if ((ret = rsslCloseChannel(sckt, &error)) < RSSL_RET_SUCCESS)
...
if (sendPing(clientSessions[i].clientChannel) != RSSL_RET_SUCCESS)
...
while (retval > RSSL_RET_SUCCESS)
Every single permutation of comparison to what one would think is a boolean status.

zergstain
Dec 15, 2005

How do I linked list?
code:

    t = *headp;
    while (t != NULL && t->asof != asof)
        t = t->next;

     if (t == NULL) {
        t = xcalloc(1, sizeof (struct saves));
        t->count = 1;
        t->asof = asof;
        if (*headp == NULL) {
            assert(tail == NULL);
            *headp = tail = t;
        } else {
            assert(tail != NULL);
            tail->next = t;
            tail = t;
        }
    }

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.

Bunny Cuddlin
Dec 12, 2004
do Hardware Horrors count? It's Ouya so I'm going to assume yes....

JazzFlight posted:

This is loving amazing.
Xbox 360 Controller:


PS3 Controller:


OUYA "Stradivarius" Controller:


Dead zones, what dead zones???

Adbot
ADBOT LOVES YOU

Opinion Haver
Apr 9, 2007

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply