Can you do this? Folders with same name

This post is not related to coding/development per se, but it’s fine to put in some fun posts once in a while.

Can you make multiple folders of the same name at the same location?

I can…

same_folder_names_1
5 folders with the “same” name at the same location

🙂

There is no photo-shop or any other type of editing in play here.

Simple things I like about C++11

Note: Some of these features might not be supported by your compiler.

1)  Keyword ‘auto’ – the type comes from the initialization.

A simple example:

auto rand_rc = new std::set<UINT64>;

The compiler deduces the type of ‘rand_rc‘ as ‘std::set<UINT64>*‘.

Now take a look at this:

void printErrorsInMap( map< int, set<UINT64>* > & errorMap )
{
for (auto iter = errorMap.begin(); iter != errorMap.end(); ++iter)
{
cout << “Errors for RC #” << iter->first << endl;

}
}

Here, the type of iter is automatically deduced as map< int, set<UINT64>* >::const_iterator.
How convenient is that!!

No need to write the long types and there’s no room for any issue related to type-safety… you see, the compiler makes the best decision.

2)  nullptr
A type nullptr_t especially-created for the null pointer (of any type).

No longer the need to use that potentially un-safe NULL – which can be an int also.

With the nullptr you CANNOT say:
int invalid_type = nullptr;

3)  Static Assertion.
An assertion that happens at compile-time.

static_assert(const_expr, string); Continue reading “Simple things I like about C++11”

Rules for Developing Safety Critical Code

Came across a nice paper by NASA/JPL scientist Gerard Holzmann on coding guidelines.

Fun Notes:

  • Interestingly, I recently wrote a couple of posts on the very same topics discussed in the paper – on function calls and macros – in my earlier posts. Amazing how events happen in this universe.
    🙂
  • I’ve worked on a project in which I blatantly broke the first rule – by using setjmp/longjmp to gracefully handle asserts and error-conditions.

Here’s the link to the paper The power of Ten — Rules for Developing Safety Critical Code.

Function calls – Speed Breakers

I recently worked on a project where my primary objective was to improve the performance of the software – increase the speed
We use Intel VTune Amplifier for profiling.

I started by first studying the code and then went on to profile it. As expected, I found many types of hot-spots. But in this post I’m going to discuss the performance hit taken due to function calls.

[ Please… I’m not advocating anything against functions… they’re great with all sorts of advantages ranging from clarity to modularity… But sometimes, they are unnecessary or sometimes their call-count can be decreased, ummm, let me explain… after all that’s the purpose of this post ]

OK, there was this function which was called around thousands to millions to 10s of millions of time depending on the input size. Lets call it high_frequency_func().

Now, high_frequency_func() itself was very well written by the original author – had very less to no scope for improvement. That made me go into a minor paralysis mode (where I just stare at something with sharp thoughts buzzing around in my mind) for a couple of seconds.

I realized that the only option to make some performance gains here was to somehow reduce the total number of times high_frequency_func() was getting called i.e. make it a “low_frequency_func()“.
[ note: high_frequency_func() is called many times for each call of the caller-function ]

Why did I think that would help? Well, read on… Continue reading “Function calls – Speed Breakers”