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
pseudorandom name
May 6, 2007

Well, not quite the same, a smart pointer/COM object/Objective C object the reference count directly controls object lifetime, but in the page cache the reference count controls whether the page is eligible for eviction. Similar basic principle, though.

Adbot
ADBOT LOVES YOU

Doctor w-rw-rw-
Jun 24, 2008

pseudorandom name posted:

Well, not quite the same, a smart pointer/COM object/Objective C object the reference count directly controls object lifetime, but in the page cache the reference count controls whether the page is eligible for eviction. Similar basic principle, though.

Technically this isn't entirely true. In Objective-C, dealloc is only called synchronously* when the number of releases match the number of retains by convention - it's possible to cause releases on a background thread to trigger main thread deallocation. Doing so requires a slight tweak to reference counting, as you need to atomically observe a "is deallocating" bit.

Deallocated (deallocating?) object resurrection is actually possible as well, though it's unconventional and very risky.

* I assume this is the condition that needs to be met for "directly controls object lifetime" to be true

EDIT: see the dealloc2main stuff in objc-internal.h

Doctor w-rw-rw- fucked around with this message at 17:51 on Aug 1, 2014

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



ohgodwhat posted:

Googling his email address leads me to believe that all he does is go around and submit unwanted and bad patches without any sort of testing. I can't decide if it's an over enthusiastic ten year old or someone with a mental illness.

And misunderstanding compiler options http://www.linuxquestions.org/quest...5770/page2.html

E: or maybe he just doesn't get how computers work - could be either one

tango alpha delta
Sep 9, 2011

Ask me about my wealthy lifestyle and passive income! I love bragging about my wealth to my lessers! My opinions are more valid because I have more money than you! Stealing the fruits of the labor of the working class is okay, so long as you don't do it using crypto. More money = better than!
I love C, but pointers are my worst enemy. I was writing a game engine with a 60 FPS main loop and it kept crashing badly. Couldn't figure out what the hell was happening until I realized that I kept declaring a pointer for the background music 60 times a second and never destroyed it.

Another one was when I wrote a graphics editor in 6502 Assembly language. My Save and Load routines kept crashing the computer and I couldn't figure out what the hell was going on. Turns on B0 and 80 look very much alike in a lovely font. Once I updated the CMP #$80 to CMP #$B0, my software worked just fine.

Volmarias
Dec 31, 2002

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

Munkeymon posted:

And misunderstanding compiler options http://www.linuxquestions.org/quest...5770/page2.html

E: or maybe he just doesn't get how computers work - could be either one

We've all done -j128 for the hell of it one time or another. Don't act like you haven't.

shrughes
Oct 11, 2008

(call/cc call/cc)

Volmarias posted:

We've all done -j128 for the hell of it one time or another. Don't act like you haven't.

If you use distcc it's totally reasonable.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Volmarias posted:

We've all done -j128 for the hell of it one time or another. Don't act like you haven't.

Sure, but I at least have enough self awareness to know that I shouldn't be a kernel contributor just because I figured out how to compile a linux

mjau
Aug 8, 2008

tango alpha delta posted:

Another one was when I wrote a graphics editor in 6502 Assembly language. My Save and Load routines kept crashing the computer and I couldn't figure out what the hell was going on. Turns on B0 and 80 look very much alike in a lovely font. Once I updated the CMP #$80 to CMP #$B0, my software worked just fine.
Write hex in lowercase. Problem solved :) (native assemblers on the c64 wouldn't even let you use uppercase :))

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Munkeymon posted:

Sure, but I at least have enough self awareness to know that I shouldn't be a kernel contributor just because I figured out how to compile a linux

Someone in the linked threads on the mailing list accused this person of simply trying to get their name in the commit log, but it seems like given the patience being shown, that could've happened ages ago. So I'm not really sure what this person's motive is.

tango alpha delta
Sep 9, 2011

Ask me about my wealthy lifestyle and passive income! I love bragging about my wealth to my lessers! My opinions are more valid because I have more money than you! Stealing the fruits of the labor of the working class is okay, so long as you don't do it using crypto. More money = better than!

mjau posted:

Write hex in lowercase. Problem solved :) (native assemblers on the c64 wouldn't even let you use uppercase :))

I was using a Machine Language monitor (yeah, I'm a masochist) which would only display mnemonics in upper case.

PrBacterio
Jul 19, 2000

Volmarias posted:

We've all done -j128 for the hell of it one time or another. Don't act like you haven't.
Not all of us have then gone and posted a question on a message board about why poo poo takes forever to finish before even thinking to try again with a lower value, though.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

pokeyman posted:

Someone in the linked threads on the mailing list accused this person of simply trying to get their name in the commit log, but it seems like given the patience being shown, that could've happened ages ago. So I'm not really sure what this person's motive is.

I first got my name in the Linux commit log (CREDITS at that point, I believe) by writing a pile of comments. Maybe that would be a better route for him.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Subjunctive posted:

I first got my name in the Linux commit log (CREDITS at that point, I believe) by writing a pile of comments. Maybe that would be a better route for him.

But this guy is only a Google search away for a perspective employer to see that he is a complete rear end

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

fletcher posted:

But this guy is only a Google search away for a perspective employer to see that he is a complete rear end

Yeah, he shows questionable judgment. I don't think that's in dispute at this point.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



At this point I really doubt he even knows what programming is, regardless of best practices, paradigms, or even languages. Maybe a vague idea of "I type on keyboard => thing happen", or actually it seems more like "a thing exists. any thing at all in the world, i myself am not even aware of what it is or its existence => i have apparently succeeded in every single one of my fully undefined goals - cum laude, even!"

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
From here it looks like the thought process is "I'll just ignore every piece of feedback except that which directly and obviously concerns the code", which of course entirely misses the point of, well, actually doing any of it.

Vanadium
Jan 8, 2005

Volmarias posted:

We've all done -j128 for the hell of it one time or another. Don't act like you haven't.

I've done make -j a few times thinking that it meant something like "parallelize up to a reasonable limit", only when I did that with the kernel did I realize that it's not actually limited.

Mandor
May 19, 2004

code:
public static Date getEasterDate(int year) {
	int  a = year % 19;
	int b = year/100;
	int C = year % 100;
	int P = b / 4;
	int E = b % 4;
	int F = (b + 8) / 25;
	int g = (b - F + 1) / 3;
	int h = (19 * a + b - P - g + 15) % 30;
	int i = C / 4;
	int K = C % 4;
	int r = (32 + 2 * E + 2 * i - h - K) % 7;
	int N = (a + 11 * h + 22 * r) / 451;
	int M = (h + r - 7 * N + 114) / 31;
	int D = ((h + r - 7 * N + 114) % 31) + 1 ; // +1; because we want easter monday, not sunday
	String month = "" ;
	String day = "";
	if (M < 10) {
		month = "0" + M;
	} else {
		month = "" + M;
	}
	if (D < 10) {
		day = "0" + D;
	} else {
		day = "" + D;
	}
	
	day = day + "/" + month;
	
	//return day ;
		
	Date date = null;
	try {
		date = getCurrentDateFormatter("dd/MM/yyyy").parse(day + "/" + year);
	} catch (ParseException e) {
		e.printStackTrace();
	}
		
	return date;
		
}
I especially like that one comment, it really ties the entire thing together.

Mandor fucked around with this message at 11:36 on Aug 4, 2014

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

Mandor posted:

I especially like that one comment, it really ties the entire thing together.

It's even worse when you realize it's there because someone copy-pasted the algorithm for Easter from somewhere else, without attributing the source, so you have a potential copyright violation there.

qntm
Jun 17, 2009
Easter is a coding horror.

Skuto posted:

It's even worse when you realize it's there because someone copy-pasted the algorithm for Easter from somewhere else, without attributing the source, so you have a potential copyright violation there.

This algorithm seems to be from 1877. It's probably public domain??

qntm fucked around with this message at 11:43 on Aug 4, 2014

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

qntm posted:

This algorithm seems to be from 1877. It's probably public domain??

That's why I wrote "potential". If there'd been a link to the origin, you'd have known instantly.

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.
It's also buggy, isn't it?

http://en.wikipedia.org/wiki/Computus#mediaviewer/File:Easter_Distribution.png

Easter can be on the 31st of March.

PIGEOTO
Sep 11, 2007

One of my co-workers is looking for a new job after being with the company for a single year. He is in a particularly lovely team, however, and I can see why he's leaving. Case in point: His managers told him to stop using 'shared_ptr' and to remove all references of it from his code with the reasoning that 'shared_ptr causes memory leaks'.

Yes, because raw pointers and heap allocations don't cause memory leaks. No, it's the shared_ptrs you see, they're the REAL memory leakers!

Sometimes I think I must've been really lucky to get put in a team where my manager isn't a fossilised relic from the 80s.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

qntm posted:

Easter is a coding horror.


This algorithm seems to be from 1877. It's probably public domain??

Copyright is about the expression, not the idea. If I write an implementation of the Easter algorithm today, the copyright clock starts today. (It's not such a trivial algorithm that there's only one way to express it, IMO.)

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
To be fair, if you're writing new code instead of wrangling smart pointers into existing code, you probably shouldn't be using shared_ptr.

seiken
Feb 7, 2005

hah ha ha

Jabor posted:

To be fair, if you're writing new code instead of wrangling smart pointers into existing code, you probably shouldn't be using shared_ptr.

I hope there's an implicit "because unique_ptr" exists on your post, but there are still lots of places where shared_ptr is a good choice.

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

seiken posted:

I hope there's an implicit "because unique_ptr" exists on your post, but there are still lots of places where shared_ptr is a good choice.

Shared, reference counted pointers and auto/unique pointers aren't even close to the same thing let alone they solve similar problems.

I think there's some idea that using shared_ptr means "you don't understand your object lifetimes so you suck". Personally I'll take shared_ptr as a good working convenience over having to do the latter and getting it wrong. And so did everyone who designed reference counted languages, I guess.

(My own code seems to mostly use it when multiple threads are involved, because gently caress dealing with lifetime issues and thread shutdown orders)

seiken
Feb 7, 2005

hah ha ha
Shared and reference counted pointers are the same thing. That's how shared_ptr works. Anyway, no, you really should use unique_ptr any time your objects are obviously a tree.

shrughes
Oct 11, 2008

(call/cc call/cc)

PIGEOTO posted:

One of my co-workers is looking for a new job after being with the company for a single year. He is in a particularly lovely team, however, and I can see why he's leaving. Case in point: His managers told him to stop using 'shared_ptr' and to remove all references of it from his code with the reasoning that 'shared_ptr causes memory leaks'.

Given that this is all I know about your coworker, I'm betting he was using them instead of properly thinking properly about object lifetimes. Maybe he also did cause memory leaks. Having circular points-to-a relationships is a bit of a smell on its own, too.

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

seiken posted:

Shared and reference counted pointers are the same thing. That's how shared_ptr works.

I should've said "shared/reference counted pointers" I guess but I really didn't think someone would manage to read the obviously wrong meaning in that sentence.

quote:

Anyway, no, you really should use unique_ptr any time your objects are obviously a tree.

Not sure what the structure of your objects has to do with figuring out ownership semantics?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Skuto posted:

Not sure what the structure of your objects has to do with figuring out ownership semantics?

If you have a tree, then each node has exactly one reference to it, so you don't need to count them. The lifetime is bounded by that of its parent, and the automatic cascade of destruction triggered by the root or subtree-root suffices.

When it starts to be a tree-with-exceptions ("let's share this one case to save space...") is when you start taking nips out of your bourbon flask during compiles and randomly keying cars in the parking lot.

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

Subjunctive posted:

When it starts to be a tree-with-exceptions ("let's share this one case to save space...") is when you start taking nips out of your bourbon flask during compiles and randomly keying cars in the parking lot.

It's called a DAG. :colbert:

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.
Thanks. I was thinking of the case with multiple threads, where the structure of the objects is a bit disconnected from the multiple ownership issue, and you don't necessarily want to scope thread lifetimes to object lifetimes.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Zopotantor posted:

It's called a DAG. :colbert:

If you're lucky, it is.

PIGEOTO
Sep 11, 2007

shrughes posted:

Given that this is all I know about your coworker, I'm betting he was using them instead of properly thinking properly about object lifetimes. Maybe he also did cause memory leaks. Having circular points-to-a relationships is a bit of a smell on its own, too.

A manager outlawing all use of shared_ptr or any other kind of smart pointer mechanism is pretty bad. Yeah you can use them badly, but that's no reason to never use them at all.

I probably wasn't clear enough that *_ptr classes are things their team aren't allowed to use, in any situation, despite having the ability to, because I guess they can cause a circular leak if someone uses them improperly.

hobbesmaster
Jan 28, 2008

He banned unique_ptr?

seiken
Feb 7, 2005

hah ha ha
Well, if you construct a unique_ptr from some other raw pointer, and keep around the the other pointer and delete it later, you might get a double delete, so clearly this technology is too dangerous for the likes of man

seiken fucked around with this message at 17:30 on Aug 4, 2014

Spatial
Nov 15, 2007

std::make_unique :c00l:

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Not quite the horror of C pointers (which is kind of a horror in itself) but I've been doing some client work that involves importing Purchase Orders from a large online marketplace. Tucked away in the documentation is:

quote:

NOTE: We >strongly< suggest you append MM/DD/YYYY to all PO Numbers originating from our system because we cannot guarantee that they will be unique.

Sure, no big. Why would you even want unique PO numbers anyway?

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

This "*_ptr is haaaard, man" stuff is why most C++ people need to use Rust instead :v:

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