Tom Lachecki

(Tomalak Geret'kal)


Second Invite

Letter from the University of Nottingham's department of "External Relations and Communications" I received in the post this morning:

Since graduating from The University of Nottingham no doubt you've either started working or are thinking about plans for the future. But have you considered continuing your studies either at Masters or PhD level? To give you an idea of all the opportunities on offer, we'd like to invite you to attend our Postgraduate Open Day on Wednesday 12th November 2008.

The letter goes on, and included in the same envelope is a flashy invitation on thick card.

The intention is all well and good, but when picking out student information from a database of recent graduates, is it really that hard to cross-check it against a database of continuing students? I'm already enrolled for an MSc course there, and it starts on Monday. Now I kind of feel as if either my personal status is being forgotten, or my enrolment has been wiped from history.

What a horrible waste of paper and resources.

Tags: , ,
Permalink | No Comments  
There's No Place Like Homes

Today in "Why New Facebook Sucks", the geniuses behind the newest incarnation of everybody's favourite social networking website have added a very useful item to the top-most navigation menu: a menu option that does exactly the same thing as the one next to it.

I have become used to clicking the item next to the "facebook" logo (which goes to the Home page) to go straight to my profile. Now, I have to go past a "Home" link which, er, also goes to the Home page (figure A).

At a time when the lack of available space in the cluttered interface is forcing the designers to cram icons into the lower-most navigation menu (figure B) this decision seems a little, well, whacked to say the least.

This could go some way to help explain the 269,585 members of just one "against the new version of Facebook" Facebook group. There are 215,701 members in another. And there are more.

Tags: ,
Permalink | No Comments  
Stargate Atlantis: The Queen

Last night's episode of Stargate Atlantis was the eighth in the final season, and saw a whole new role for Rachel Luttrell.

spoilers

I definitely enjoyed that ep and it would be good to see more of that dynamic before season's end.

It's a shame Scifi brought back the 10-second intertitle, though. I guess they figure the fans don't have any leverage now that the show's in its final season, and that extra minute of ad money could get a couple of execs new cars.

Tags: ,
Permalink | No Comments  
Surfing Tidal Forces

On IRC today, everyone and his dog is chatting about black holes. This may or may not be because the LHC was successfully activated today and we could all be ripped apart by microtidal forces at any moment.

But I got to thinking, what if they create a black hole and it puts the universe into equilibrium? The universe stops expanding, then we create another one and things start to come together again. We could bring other galaxies closer to us so that we might actually be able to reach them and chat to aliens.

I'm sure they'd love that. "How did you get here? [..] You did WHAT?!"

Nothing could possibly be wrong with this idea.

Happy Big Bang Day.

Tags: , ,
Permalink | No Comments  
Terrists: We Gonna Find 'em And Smoke 'em

McCain says, "we are winning in Iraq". Winning against who? How are we winning?

It disturbs me greatly that the GOP is ahead in the polls… at least according to CNN.

Tags: , ,
Permalink | [2] Comments  
Tomalak's Tuesday Tip #2: String Streams

OK, so this tip thing doesn't look like it's going to be weekly. But hey, close enough right?

This week I want to talk about two classes that are both part of the C++ Standard Library, both do similar things and yet are fundamentally different. String streams.

The modern way

If you write decent C++ you may already be familiar with std::stringstream from the <sstream> header. It provides a buffered stream interface over the standard std::string object, allowing very easy manipulation of the underlying buffer. In particular, it's often used due to the large number of conversion opportunities exposed by the stream interface.

For example if you wanted a numeric string in standard C, you'd probably have done something like this:

Annoyingly, you had to pre-allocate the amount of memory that you thought would be required. In the example above that's easy: I knew I needed space for three characters and the terminating NUL, so I allocated four characters for the C-string.

But it wasn't always that easy. If you wanted to take unpredeterminable input and put that into a string, you'd have to simply guess at the space required, and if there wasn't enough that was just too damn bad. But hey, at least you could put almost anything into it thanks to printf and its friends.

Then along came C++ with its standard string wrapper, with its dynamic allocation and, most importantly, dynamic resizing. You can concatenate with a single operator and you can add as much data to it as you like without worrying about running out of pre-allocated buffer space.

std::string concatenation is great. But the class is not very good at implicit conversion:

Thankfully, the streams interface is great at this as it has all sorts of varieties of conversion loaded into the << operator. Since stringstream is a stream buffer built over a string, we can use it to easily manipulate the underlying string in ways the string itself would never allow us to:

Of course, the above is a silly simplistic example as we could have written std::string str = "Hello 5 worlds" directly, but the technique is useful when you don't know in advance what that number's going to be:

The simplicity of this approach seems like a lifesaver, and is in fact used all the time when people would in the past have used sprintf with a fixed C-string buffer.

However, there is one oft-overlooked flaw with this approach. stringstream.str() returns a copy of the string buffer, not a reference. In fact, there is no way to get a reference to the string buffer of a stringstream. This means that every time you pull a string from a stringstream, the data is copied in memory.

It might not seem like such a big deal unless you're frequently creating a stringstream purely to use its conversion facilities, then grabbing the underlying string for further use. You're wasting memory and CPU cycles.

Looking backwards

There exists a standard alternative that a lot of people don't know about, with the similar name discouraged by experts for at least eight years.

This recommendation may seem a little premature when you consider that strstream is not being dropped from the upcoming C++0x and the next standard version after that is not expected until we approach 2020.

But more importantly, what most of these experts opt not to mention is that the underlying data of a strstream is an old C-style character array rather than a C++ string object. Because of this, we get direct access to the data without having to go through an protective layer of abstraction.

Specifically, where stringstream.str() gives us a copy of a string object (which copies the string), strstream.str() gives us a copy of a pointer to characters (which does not).

We'd still have to create a copy of the C-style string if we wanted to use all the functionality of C++ strings because std::string doesn't give us a choice, but now we have a C-style string that wasn't copied and we can do what we like with it.

A complicated manipulation of strstream's underlying buffer might look like this:

So it's not beautiful; but it does demonstrate the added power of direct stream buffer access.

If you like the options provided by the stream interface and find yourself concerned that you're copying string data needlessly, or have a need to modify the underlying buffer data, stop and think for a moment before throwing strstream mericilessly to the hounds of time. Because it has use yet.

Bootnote

I apologise for the use of the past tense when referring to C. Yes, I know the language is still very much alive and kicking and that plenty of people still use it. However, in this article's C++ context it's merely a precursor. So you'll just have to get used to it.

Tags: , ,
Permalink | [3] Comments  
Returning Shadows?

I love this unassuming shot of Sarkozy and Medvedev's shadow on the BBC's "day in pictures" feature:

The caption reads:

French President Nicolas Sarkozy visits Moscow to discuss the crisis in Georgia with Russian President Dmitry Medvedev, whose shadow is seen on the right.

Nothing says "dangerously looming shadowy nation" quite like a foreign leader's silhouette pitted alongside the brightly-lit EU president. Really this is a pitiful attempt at fear-mongering, and I resent it.

Tags: ,
Permalink | No Comments  
An Open Letter To The Internets

It's fairly standard practice online when one makes a typo to mark a correction with an asterisk. For example:

John says: so im going to the cinmena tomorrow u wanna come? John says: cinema*

This strategy (supposedly necessary even amidst a sentence full of grammatically dubious abbreviations) can be taken one step further. If you find yourself in a channel named #C++, #PHP and such like on IRC, you may well see people writing regular expressions to "fix" their previous line. For example:

<john361> and do send out emails using a php function? <john361> s/do/to

The second line is a regular expression substitution. The 's' means substitution, the 'do' is the text to change and the 'to' is the text to change it to. So anyone reading john361's messages should apply the "fix" in their minds and read the original text as:

<john361> and to send out emails using a php function?

Unfortunately, this is incorrect. I have yet to figure out why so many people are doing this at the moment, but there's an epidemic of omitting terminating regular expression delimiters.

So I'm going to say this once, and once only:

Thanks for reading.

Tags: , , ,
Permalink | [6] Comments  
Brand Backs Barack

Russell Brand publicly threw his support behind Barack Obama at the MTV Video Music Awards in LA this weekend with some colourful language.

Some people, I think they're called racists, say America is not ready for a black president. But I know America to be a forward-thinking country because otherwise why would you have let that retarded cowboy fella be president for eight years. We were very impressed. We thought it was nice of you to let him have a go, because, in England, he wouldn't be trusted with a pair of scissors.

You've gotta love British exports. Still, he's completely right of course.

Bootnote

If any further proof of Brand's craziness were ever needed, he also made a comparison of Britney Spears as a messiah figure:

Consider this the resurrection of Britney Spears. If there was a female Christ, it's Britney.

Like, huh?

Tags: ,
Permalink | No Comments  
Amazon's Precognitive Marketing

I don't know how they did it but Amazon emailed me product recommendations that aptly describe my tastes, despite my having never bought a book nor a religious item from them. Eh, maybe that's why.

Impressive.

Permalink | No Comments  

Next Page »