News

Quick Q: Is std::vector so much slower than plain arrays?

Quick A: A vector isn’t slower than an array when they do the same things. But it lets you do much more…

Some time ago on SO:

Is std::vector so much slower than plain arrays?

Using the following:

g++ -O3 Time.cpp -I <MyBoost>
./a.out
UseArray completed in 2.196 seconds
UseVector completed in 4.412 seconds
UseVectorPushBack completed in 8.017 seconds
The whole thing completed in 14.626 seconds


So array is twice as quick as vector.

But after looking at the code in more detail this is expected; as you run across the vector twice and the array only once. Note: when you resize() the vector you are not only allocating the memory but also running through the vector and calling the constructor on each member.

Re-Arranging the code slightly so that the vector only initializes each object once:

std::vector<Pixel>  pixels(dimensions * dimensions, Pixel(255,0,0));

Now doing the same timing again:

g++ -O3 Time.cpp -I <MyBoost>
./a.out
UseVector completed in 2.216 seconds


The vector now performance only slightly worse than the array. IMO this difference is insignificant and could be caused by a whole bunch of things not associated with the test.

I would also take into account that you are not correctly initializing/Destroying the Pixel object in the UseArrray() method as neither constructor/destructor is not called (this may not be an issue for this simple class but anything slightly more complex (ie with pointers or members with pointers) will cause problems.

Presenting Code

How should we present code? - is the question.

Presenting Code

by Jens Weller

From the article:

At CppCon 2015 I decided to give a small lightning talk on how to present code in the coming year. This was a reflection on visiting many C++ related conferences and seeing many talks live and online...

Recommendations to speed C++ builds in Visual Studio--Sridhar Madhugiri

This post discusses features, techniques and tools you can use to reduce build time for C++ projects:

Recommendations to speed C++ builds in Visual Studio

by Sridhar Madhugiri

From the article:

Developers invoke build frequently while writing and debugging code, so improvements here can have a large impact on productivity. Many of the recommendations focus on this stage...

Announcing the lounge track for Meeting C++ 2016

Something new at Meeting C++ this year: a track dedicated to meetups!

Announcing the Lounge Track

by Jens Weller

From the Article:

If you look at the schedule, you might notice two changes. Most visible is that there is now a floor plan for the conference. The other one is very subtle: the breaks now have a hint for a 6th track.

ACCU 2017 Call for session -- ACCU

The ACCU 2017 is now putting together its program, and they want you to speak on C++. The ACCU has a strong C++ track, though it is not a C++-only conference. If you have something to share, check out their

Call for Sessions

by the ACCU

From the article:

We have a long tradition of high quality sessions covering many aspects of software development, from programming languages (e.g. C, C++, D, C#, Go, Rust, Clojure, Erlang, Groovy, Haskell, Java, JavaScript, ECMAScript, Python, Ruby, Scala, etc.), and technologies (libraries, frameworks, databases, etc.) to subjects about the wider development environment such as testing, architecture and design, development process, analysis, patterns, project management, and softer aspects such as team building, communication and leadership. See the 2016 schedule for examples.

The Call for Sessions lasts 7 weeks and will close at midnight Friday 2016-12-02.

CppCast Episode 75: Robotics with Jackie Kay

Episode 75 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Jackie Kay from Marble to discuss the use of C++ in the Robotics industry and some of the unique challenges in Robotics development.

CppCast Episode 75: Robotics with Jackie Kay

by Rob Irving and Jason Turner

About the interviewee:

After spending her childhood wanting to become a novelist, Jackie switched over from writing stories to writing code during college. She graduated from Swarthmore College in 2014 with a Bachelor's in Computer Science and went on to work at the Open Source Robotics Foundation for two years, supporting Gazebo, a physics simulator for robotics R&D, and ROS, an open source application framework for robotics development. She recently started as an early employee at Marble in San Francisco, a startup working on autonomous delivery.

Jackie was a speaker at CppCon 2015 and 2016 and a volunteer at C++ Now 2016 and frequently attends the Bay Area ACCU meetups. Her hobbies include rock climbing, travelling, and reading (books, not just blog posts).

Visiting variants using lambdas (2: recursive variants) -- Vittorio Romeo

The article addresses the problem of lambda-based `std::variant` and `boost::variant` recursive visitation. Starting from the definition of a "recursive variant", it shows the concept and implementation behind a `make_recursive_visitor` variadic function that can be used to create "local" visitors by using lambdas.

visiting variants using lambdas - part 2

By Vittorio Romeo

From the article:

A "recursive" variant is a variant which can contain itself, and can be used to represent recursive structures. [...] Bringing algebraic data types from the functional programming world into C++ isn't enough - we're also going to adopt another powerful construct: the Y Combinator. [...] Now we can put everything together to finally visit a recursive variant using lambdas!