If you see this post, the move to my new web hosting provider was successful.
Last month, my wife and I vacationed to California. Here are some pictures from that vacation:
What’s wrong with the following code?
-
template<typename T1, typename T2>
-
struct my_pair
-
{
-
typedef T1 first_type;
-
typedef T2 second_type;
-
-
my_pair() : first(T1()), second(T2()) {}
-
my_pair(const T1& v1, const T2& v2) : first(v1), second(v2) {}
-
-
T1 first;
-
T2 second;
-
};
-
-
template<typename T1, typename T2>
-
inline bool operator<
-
(
-
const my_pair<T1, T2>& x,
-
const my_pair<T1, T2>& y
-
)
-
{
-
return (x.first < y.first || x.second < y.second);
-
}
-
-
void f()
-
{
-
typedef my_pair<…, …> key_type;
-
typedef … value_type;
-
typedef std::map<key_type, value_type> map_type;
-
-
map_type map;
-
// Use map
-
}
I recently wrote a piece of code that looked something like the following:
-
static const int NUM_TOTAL_VALUES = …;
-
typedef … T;
-
-
// Create vec and reserve NUM_TOTAL_VALUES spaces for later insertion
-
std::vector<T> vec(NUM_TOTAL_VALUES);
-
-
// Insert values into vec
-
for (int i = 0; i != NUM_TOTAL_VALUES; ++i)
-
vec.push_back(…);
-
-
// vec should now have NUM_TOTAL_VALUES values in it (but doesn’t!)
What’s wrong with this code?
Let’s say you have the following unmanaged code:
-
#pragma unmanaged
-
-
class Stream { … }; // Conceptual stream class
-
-
class StreamWriter
-
{
-
public:
-
StreamWriter(Stream* pStream) : m_pStream(pStream) {}
-
~StreamWriter() { /* Use m_pStream in some way */ }
-
-
…
-
private:
-
Stream* m_pStream;
-
};
-
-
void f()
-
{
-
Stream stream;
-
StreamWriter streamWriter(&stream);
-
-
// Use streamWriter
-
-
// streamWriter is destroyed
-
// stream is destroyed
-
}
Note that StreamWriter’s destructor uses m_pStream (perhaps by flushing the stream). This means that the order of destruction is important — StreamWriter must be destroyed before its underlying Stream is.
Now let’s try to write and use some simple managed C++ wrappers for these classes:
-
#pragma managed
-
-
public __gc class ManagedStream
-
{
-
public:
-
ManagedStream() : m_pStream(new Stream) {}
-
-
// NOTE: This is a finalizer, not a determinstic destructor
-
~ManagedStream() { delete m_pStream; }
-
-
public private: // Make accessible by ManagedStreamWriter
-
Stream __nogc* m_pStream;
-
};
-
-
public __gc class ManagedStreamWriter
-
{
-
public:
-
ManagedStreamWriter(ManagedStream* pStream) :
-
m_pStreamWriter(new StreamWriter(pStream->m_pStream)) {}
-
-
// NOTE: This is a finalizer, not a determinstic destructor
-
~ManagedStreamWriter() { delete m_pStreamWriter; }
-
-
private:
-
StreamWriter __nogc* m_pStreamWriter;
-
};
-
-
void f()
-
{
-
ManagedStream stream = __gc new ManagedStream();
-
ManagedStreamWriter streamWriter =
-
__gc new ManagedStreamWriter(stream);
-
-
// Use streamWriter
-
-
// GC will clean up stream and streamWriter
-
}
See the problem?
Courtesy of Dave, here’s a script I put into crontab to perform nightly full backups of my WordPress MySQL database:
#!/bin/sh DATE=`date +%Y-%m-%d` BACKUPDIR=$HOME/.mysql-backup USERNAME=XXXXX # TODO PASSWORD=XXXXX # TODO DATABASE=XXXXX # TODO if [ ! -d $BACKUPDIR/$DATABASE ]; then mkdir $BACKUPDIR/$DATABASE fi mysqldump --user=$USERNAME --password=$PASSWORD $DATABASE > $BACKUPDIR/$DATABASE/$DATE.dump bzip2 -9 $BACKUPDIR/$DATABASE/$DATE.dump
Yesterday, Home Depot, the world’s third-largest retailer by sales, announced a big change: Mr. Nardelli was leaving the company, taking an exit package valued at about $210 million, including $20 million in cash severance.
Lublin, Joann S., Ann Zimmerman, and Chad Terhune. Behind Nardelli’s Abrupt Exit [$]. The Wall Street Journal 2007 Jan 4: A1.
Home Depot’s share price fell 8% during Mr. Nardelli['s] tenure, which began in December 2000. The company is locked in a fierce battle with Lowe’s, which boasts newer, brighter stores and a better image with many shoppers. Lowe’s stock has risen 188% in the past six years.
Ibid.
Mr. Nardelli moved to cut back on higher-paid full-time employees with experience as plumbers or handymen, and to rely more on part-time workers with less experience answering home-improvement questions from customers. Frequently, Mr. Nardelli found himself fending off questions about deteriorating customer service and about whether cost-cutting was the cause of that.
Ibid.
[As part of his exit package negotiation,] Mr. Nardelli submitted a one-page list of perks he was willing to drop, including personal use of the six corporate jets…
Ibid.
…guaranteed $3 million annual bonus… [emphasis mine]
Ibid.
Much of [Mr. Nardelli's compensation] package is due to the rich employment contract he negotiated with the Home Depot board before leaving General Electric Co., where he was one of three finalists to succeed Jack Welch. Mr. Welch convinced his board to give all three finalists large batches of stock options, telling board members they would have to make good on only one man’s options, one director says. Upon leaving GE, the board was told, the two runners-up likely would use those awards to negotiate pay at their next jobs — which is exactly what Mr. Nardelli and James McNerney, who is now CEO of Boeing, did.
Ibid.
“Some defenders of CEO pay argue that CEOs are rewarded for increasing the stock or the overall value of the company, but judging by today’s market reaction, Mr. Nardelli’s contribution to raising Home Depot’s stock value consists of quitting and receiving hundreds of millions of dollars to do so,” [said Barney Frank (D., Mass.), chairman designate of House Financial Services Committee]
Ibid.
Due to a tragic loss of data, along with incessant spam problems, I have disabled all comments on my blog.
Update 2007-01-16 9:54AM: I have reenabled comments, but all previous comments were lost. Yet another case study in the importance of backups.
Recent Comments