Monday, July 21, 2008
Saturday, May 31, 2008
Thursday, May 22, 2008
Virtual destructor
My fan base quickly pointed out that in the example code I sent through valgrind the other day, that class Derived didn't allocate any dynamic memory, and that not calling its destructor would not have been expected to leak memory. All of the comments I got suggested that if I had allocated some block of dynamic memory, either with a stl vector or a raw C-style array inside the constructor, and destroyed it in the destructor, the memory would be leaked in a call to the (non-polymorphic) base class dstor.
I went ahead and coded up the suggestion and found, yes, valgrind detects the leaked memory.
This makes me wonder, though: how the hell does delete know how large the thing is that its deleting?
I went ahead and coded up the suggestion and found, yes, valgrind detects the leaked memory.
This makes me wonder, though: how the hell does delete know how large the thing is that its deleting?
Saturday, May 17, 2008
I wish I could quit you
I got stuck in emacs while using cygwin. C-x C-c did nothing. So I tried M-x to type out a bunch of possible "exit" commands.
I tried:
quit
exit
leave
These are not meaningful ways to end emacs.
How do you quit?
M-x save-buffers-kill-emacs
Thank you google. If not for you, I might still be trapped in emacs hell.
I tried:
quit
exit
leave
These are not meaningful ways to end emacs.
How do you quit?
M-x save-buffers-kill-emacs
Thank you google. If not for you, I might still be trapped in emacs hell.
Thursday, May 15, 2008
valgrind non-virtual dstor leak bug
I ran valgrind on the following code which, you'll see, leaks the data stored in the derived class.
Valgrind does not seem to notice the leak. I'm not so happy about that.
/// test.cc
#include
class Base {
public:
virtual void blah() = 0;
~Base() { std::cout << "Base dstor" << std::endl; }
private:
int data_;
};
class Derived : public Base
{
public:
virtual void blah() {}
~Derived() { std::cout << "Derived dstor" << std::endl;}
private:
int data2_;
int data3_;
};
int main()
{
Base * bptr = new Derived;
delete bptr;
return 0;
}
..........
From the command line.
>g++ test.cc -o test.out
>valgrind --tool=memcheck test.out
==31535== Memcheck, a memory error detector.
==31535== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==31535== Using LibVEX rev 1575, a library for dynamic binary translation.
==31535== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==31535== Using valgrind-3.1.1, a dynamic binary instrumentation framework.
==31535== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==31535== For more details, rerun with: -v
==31535==
Base dstor
==31535==
==31535== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 1)
==31535== malloc/free: in use at exit: 0 bytes in 0 blocks.
==31535== malloc/free: 1 allocs, 1 frees, 24 bytes allocated.
==31535== For counts of detected errors, rerun with: -v
==31535== All heap blocks were freed -- no leaks are possible.
Valgrind does not seem to notice the leak. I'm not so happy about that.
/// test.cc
#include
class Base {
public:
virtual void blah() = 0;
~Base() { std::cout << "Base dstor" << std::endl; }
private:
int data_;
};
class Derived : public Base
{
public:
virtual void blah() {}
~Derived() { std::cout << "Derived dstor" << std::endl;}
private:
int data2_;
int data3_;
};
int main()
{
Base * bptr = new Derived;
delete bptr;
return 0;
}
..........
From the command line.
>g++ test.cc -o test.out
>valgrind --tool=memcheck test.out
==31535== Memcheck, a memory error detector.
==31535== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==31535== Using LibVEX rev 1575, a library for dynamic binary translation.
==31535== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==31535== Using valgrind-3.1.1, a dynamic binary instrumentation framework.
==31535== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==31535== For more details, rerun with: -v
==31535==
Base dstor
==31535==
==31535== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 1)
==31535== malloc/free: in use at exit: 0 bytes in 0 blocks.
==31535== malloc/free: 1 allocs, 1 frees, 24 bytes allocated.
==31535== For counts of detected errors, rerun with: -v
==31535== All heap blocks were freed -- no leaks are possible.
Wednesday, May 14, 2008
Friday, April 18, 2008
Infant waterboarding
To ghastly to believe.
http://www.cnn.com/video/#/video/bestoftv/2008/04/18/ng.polygamy.crime.cnn
http://www.cnn.com/video/#/video/bestoftv/2008/04/18/ng.polygamy.crime.cnn
Wednesday, April 09, 2008
snowboarding
Pants and I finished our third day of snowboarding at this resort an hour outside of the city. They had this deal for newbs: $100, 3 lift tickets, 3 rentals, 3 lessons. I had a blast, and so did Pants, who before our first day had never been skiing, snowboarding or even sledding. It was her first time on a snowy hill. She liked it so much, we're talking about getting a season ticket next year -- $300 for the "limited" season pass (which means, on weekends, it's not good at the sister-resort up the street -- you can still go to the sister resort on weekdays, though) or $360 for the "unlimited" (good at the sister resort at all times). Pays for itself after 6 trips since usually lift tickets are $48. I'm totally psyched.
Friday, April 04, 2008
Welfare Dad
You know this guy is just going to go out and make the same mistakes the next time 'round. Those suckling at Uncle Sam's teat tend to think they never have to assume responsibility for their mistakes.
Wednesday, February 06, 2008
Bush: "I broke the law, I dare you to impeach me"
"Let me make it very clear and to state so officially in front of this committee that waterboarding has been used on only three detainees. It was used on Khalid Sheikh Mohammed. It was used on Abu Zubaydah. And it was used on [Abd al-Rahim al-]Nashiri."
-- CIA director Michael Hayden, yesterday.
Waterboarding is torture. Torture is banned under international treaty. Bush violated international treaty. He broke the law. He should be removed from office.
-- CIA director Michael Hayden, yesterday.
Waterboarding is torture. Torture is banned under international treaty. Bush violated international treaty. He broke the law. He should be removed from office.
Twelve McCain Supporters
In all of West Virginia, only twelve people voted for John McCain. Twelve. I bet they know each other.
Of course, that's still 1% of the West Virginia vote, because only a little more than a thousand people in west virginia voted. The rest must think they live in Russia where there's no such thing as democracy.
Of course, that's still 1% of the West Virginia vote, because only a little more than a thousand people in west virginia voted. The rest must think they live in Russia where there's no such thing as democracy.
Saturday, February 02, 2008
Tuesday, January 22, 2008
Racist
"You don't like people from outside the state coming in and telling you what to do with your flag. In fact, if somebody came to Arkansas and told us what to do with our flag, we'd tell 'em what to do with the pole; that's what we'd do."
-- Mike Huckabee, while in South Carolina.
-- Mike Huckabee, while in South Carolina.
Monday, January 21, 2008
Unamerican
"I have opponents in this race who do not want to change the Constitution. But I believe it’s a lot easier to change the Constitution than it would be to change the word of the living God. And that’s what we need to do — is to amend the Constitution so it’s in God’s standards rather than try to change God’s standards so it lines up with some contemporary view of how we treat each other and how we treat the family."
-- Mike Huckabee
-- Mike Huckabee
Thursday, December 06, 2007
Flu
I've come down with a nasty case of the flu which has incapacitated me since Monday night. I've been staying home mostly so I don't infect everyone else in the lab -- but if I went in to lab, I'd get nothing done there either.
The most-likely suspect for having infected me is, of course, Pants. She came home with something from work, and ended up staying home one day. She was slightly feverish, she tells me, but mostly, it seemed like a cold. When I finally contracted it, I skipped the cold symptoms and went straight for the chills. Fevers, sweats, malaise. It always happens that if she and I catch the same thing, it knocks me out 200% worse than it does her. Most of the time, I catch something and she never catches it from me.
The worst part about being home sick is that I feel totally unproductive. I wake up at night from work dreams and can't fall back asleep.
The most-likely suspect for having infected me is, of course, Pants. She came home with something from work, and ended up staying home one day. She was slightly feverish, she tells me, but mostly, it seemed like a cold. When I finally contracted it, I skipped the cold symptoms and went straight for the chills. Fevers, sweats, malaise. It always happens that if she and I catch the same thing, it knocks me out 200% worse than it does her. Most of the time, I catch something and she never catches it from me.
The worst part about being home sick is that I feel totally unproductive. I wake up at night from work dreams and can't fall back asleep.
Monday, November 12, 2007
Hardware watchpoint in GDB
For some reason, the synatax for setting a hardware watchpoint in GDB is impossible to find in google. Or rather, there are misleading instructions on how to set the watchpoint. The instructions you'll find say "watch for when variable x gets changed by writing 'watch x'". But this never solves a memory corruption bug. At least for me.
This post is for my own purposes. I never want to waste 10 minutes searching for the proper syntax again.
Let's say I know that location 0xABCD1234 is getting corrupted.
Then the gdb command is:
> watch *((int*) 0xABCD1234)
This post is for my own purposes. I never want to waste 10 minutes searching for the proper syntax again.
Let's say I know that location 0xABCD1234 is getting corrupted.
Then the gdb command is:
> watch *((int*) 0xABCD1234)
Sunday, November 04, 2007
Mukasey
The president of the Uninted States continues to violate the constitution he swore to uphold in torturing prisoners. He has asked congress to replace his former torture-enabler, the embattled Gonzales, with a new puppet, Robert Mukasey. When Mukasey went before the Senate, he would not say that waterboarding is torture. Waterboarding is torture. Mukasey has publicly expressed his willingness to allow Bush to continue torturing, to continue breaking international treatries in violation of the constitution.
Charles Schumer, a senior democrat, is now supporting Mukasey's confirmation based on a private conversation he had with Mukasey. What's his rationale? He says that Mukasey agreed with a hypothetical: if Congress were to pass legistation saying that waterboarding is torture, then it would not be out-of-line with its constitutionally granted powers and the President wouldn't have any recourse (except of course, to veto the bill).
The logic here is tortured. Schumer seems to think this consession is a hat-tip to the separation-of-powers provisions of the constitution. When did the constitution need consessions made to it?
Moreover, its a circuitous consession. It makes congress do much more work than it needs to! Congress does not need to say that waterboarding is torture. Legal precident and human decency defines it as torture. Worst of all, if congress were to legistlate that waterboarding is torture, then it effectively grants immunity to water-boarders up until this point: "Oh, I just water boarded that guy because it wasn't illegal at the time."
Schumer is doing a grave disservice to the anit-torture camp. Why is toture so hard to stand against?
Charles Schumer, a senior democrat, is now supporting Mukasey's confirmation based on a private conversation he had with Mukasey. What's his rationale? He says that Mukasey agreed with a hypothetical: if Congress were to pass legistation saying that waterboarding is torture, then it would not be out-of-line with its constitutionally granted powers and the President wouldn't have any recourse (except of course, to veto the bill).
The logic here is tortured. Schumer seems to think this consession is a hat-tip to the separation-of-powers provisions of the constitution. When did the constitution need consessions made to it?
Moreover, its a circuitous consession. It makes congress do much more work than it needs to! Congress does not need to say that waterboarding is torture. Legal precident and human decency defines it as torture. Worst of all, if congress were to legistlate that waterboarding is torture, then it effectively grants immunity to water-boarders up until this point: "Oh, I just water boarded that guy because it wasn't illegal at the time."
Schumer is doing a grave disservice to the anit-torture camp. Why is toture so hard to stand against?
Wednesday, September 26, 2007
Religion is evil
A catholic bishop makes up a story about how condoms give you AIDS. Does he have any proof for his claim? No. Of course not. But that's the thing. Religious authority has never been constrainted by the burden of proof, so people are used to just listening to whatever lunatic ideas they have.
This bishop has blood on his hands.
This bishop has blood on his hands.
Wednesday, September 12, 2007
not surprised
The Post declares Putin's move a surprise. I disagree. He's always behaved like a dictator. Now he's just assuming the mantle.
Monday, August 20, 2007
Dead air
As we drove from North Dakota into Montana on Wednesday evening, the sun was setting and I was getting tired. We'd been driving since 9 that morning (central time) and it was almost 8 (mountain time). I scanned through the chanels on the truck's radio and stopped on a classic rock station which was finishing off some song I didn't recognize from the early 80's I figured. It went to a comercial break, but I stuck with the station because my other two options were a country station and an all-jesus-all-the-time station.
As the station returned from break, it went through its call sign
"One hundred point five. The rock."
< Dead silence >
I kept glancing down at the dial and started to chuckle to myself. They were broadcasting dead air; how embarassing. Thirty seconds passed. I was cracking up. These idiots clearly didn't have a very high value on their air time if they were letting thirty seconds go by without broadcasting anything. How unprofessional. A minute passed. I started to get a little peeved. The sun was setting into my eyes, so I adjusted the sun visor -- I was only able to see the road up to the horizon in front of me. Two minutes passed, still no music. Man, these guys seriously need work. I started to forget that I was listening to the radio. Five minutes passed. Then I finally hear
"One hundred point five. The rock"
< Dead silence >
Someone's clearly gone to take a shit after queueing up a whole bunch of music. The call signs keep coming but the music they've queued is not. Well surely their boss is listening to the radio and will jump into the booth and straighten the mess out. Five more minutes pass; my mind wanders and I start to get sleepy. Fortunately, the radio comes to its senses and I hear
"One hundred point five. The rock"
< Dead silence >
AAAAAAAAA. Play something goddamnit!
I switched to the country station.
As the station returned from break, it went through its call sign
"One hundred point five. The rock."
< Dead silence >
I kept glancing down at the dial and started to chuckle to myself. They were broadcasting dead air; how embarassing. Thirty seconds passed. I was cracking up. These idiots clearly didn't have a very high value on their air time if they were letting thirty seconds go by without broadcasting anything. How unprofessional. A minute passed. I started to get a little peeved. The sun was setting into my eyes, so I adjusted the sun visor -- I was only able to see the road up to the horizon in front of me. Two minutes passed, still no music. Man, these guys seriously need work. I started to forget that I was listening to the radio. Five minutes passed. Then I finally hear
"One hundred point five. The rock"
< Dead silence >
Someone's clearly gone to take a shit after queueing up a whole bunch of music. The call signs keep coming but the music they've queued is not. Well surely their boss is listening to the radio and will jump into the booth and straighten the mess out. Five more minutes pass; my mind wanders and I start to get sleepy. Fortunately, the radio comes to its senses and I hear
"One hundred point five. The rock"
< Dead silence >
AAAAAAAAA. Play something goddamnit!
I switched to the country station.
Subscribe to:
Posts (Atom)