fibonacci sequence

We all learned about the Fibonacci numbers in school. If you need a refresher course, the integers in the Fibonacci sequence start with 0 and 1. Each subsequent number is the sum of the previous two, so the third number in the sequence is 1, the fourth number, is 2, the fifth number is 3, and so on. The Fibonacci spiral is something we see every day in nature but never really pay much attention to. However, an amazing YouTube video called “Nature By Numbers” puts the mathematical sequence into perspective for us.

Artists and architects have been using geometrical and mathematical properties since ancient times. We’ve seen it used by architects from Ancient Egypt, Greece, and Rome, and by Renaissance artists like Michelangelo and Da Vinci. However, Vila wanted to showcase how these properties are used in nature.

(more…)

The Unix revolution

This November, the Unix community has another notable anniversary to celebrate: the 40th birthday of the first edition of Ken Thompson and Dennis Ritchie’s Unix Programmers Manual, released in November 1971. Producing the document was no easy task, because at that point the Unix operating system grew by the week; budding aficionados added new commands and features to the system on a regular basis.

“The rate of change of the system is so great that a dismayingly large number of early sections [of the text] had to be modified while the rest were being written,” Thompson and Ritchie noted in their introduction. “The unbounded effort required to stay up-to-date is best indicated by the fact that several of the programs described were written specifically to aid in preparation of this manual!”

That’s why Unix timelines are fun to read—they give a sense of how quickly the system collaboratively evolved. But some of them either skip or mention without explanation a government decision that, in retrospect, paved the way not only for Unix, but perhaps for the open source movement as well: the 1956 Consent Decree between the United States Department of Justice and AT&T. (more…)

building boost libraries

boost is mostly header only library, there are a few libraries like file-system, threads, chrono that abstract the OS/Runtime Library concepts, and few have been implemented in cpp files regex for an example. These few libraries need to be built before you can use them.

boost comes with its own build engine, bjam, which is configured to build it with relevant dependencies and install the libraries in designated locations.

I am not getting into boost-bjam in this post, however I will cover building boost library using bjam with VS 2010 SP1.

Extract the latest boost version, at the time of writing this post the version happens to be 1.47, in some directory, may be f: boostboost_1.47, let’s call this a root directory. bjam is distributed as source along with boost, to build boost we need to build bjam first.

Open a VS 2010 SP1 Command Prompt, that would be VS 2010 Tools (either open x64 or 32), on that command prompt cd to root directory. Execute the command bootstrap.bat, this will build the bjam engine and place the bjam.exe in your root directory.


Once done building bjam, again on the same command prompt execute the command bjam and after a while you are all set. This command generates static libraries from boost code to be directly linked against you application.

Two lib files are generated for each library built, in case of chrono these are:

  • libboost_chrono-vc100-mt-1_47.lib ( this is release version)
  • libboost_chrono-vc100-mt-gd-1_47.lib ( this is debug version)

you will be required to provide these as input to linker, depending upon the release or debug version, to build and link

Related articles

vector: reserve with care…

vectors, std::vector, are contiguous-memory sequential dynamic containers. That means if the vector has to grow then it will re-allocate the required memory to hold elements and then copy these over in the new memory, that is one of the reasons that for any type to be contained in vector must define default, copy constructors and assignment operator.

However there is a way to work around this reallocation problem if we know before hand how much the vector is going to grow. The method reserve does the job:

std::vector<int> vec;
vec.reserve(10);
for( int idx = 0; idx < 10; ++idx )
{
    vec.push_back(idx);
}

This contrived example shows how to use the reserve method, but in real life we generally don’t reserve the new containers, but there may be a container that is passed in as one of the arguments and you are trying to fill-it up:

    std::vector<int> vec;
    vec.reserve(10);
    for( int idx = 0; idx < 10; ++idx )
    {
        vec.push_back(idx);
    }

    vec.reserve(10);
    for( int idx = 0; idx < 10; ++idx )
    {
        vec.push_back(idx);
    }

This looks quite intuitive, however it is flawed when reserving the memory. vec.reserve(10); does not imply reserve 10 more slots it means just reserve 10 slots. What that means is if your container already has 12 elements vec.reserve(10); becomes no-op, cause the container already has more memory allocated than what you required. If your intention was to resize the vector then there is an explicit method named resize.

The correct code should be:

    std::vector<int> vec;
    vec.reserve(10);
    for( int idx = 0; idx < 10; ++idx )
    {
        vec.push_back(idx);
    }

    vec.reserve(vec.size() + 10);
    for( int idx = 0; idx < 10; ++idx )
    {
        vec.push_back(idx);
    }