Intoday's post, I like to address a topic already discussed by others. However, in classes or code reviews, I still see the confusion. That's why I want to highlight this once more. What I'm talking about? The difference between push_back and emplace_back or better when using which function of the std::vector.
People often tell me they use emplace_back when this topic comes up for performance reasons. Because it is faster than push_back as it creates the object in place. And that is true. However, when I look at the code, I see that the statement does not apply to the code written. Let's use an example and test your knowledge.
The interesting part starts in B, where I use push_back to add a newly created temporary object to my vector v. In C, I use a different approach with emplace_back to add a newly created temporary object to v. Last, in D, I use a variation of C, emplace_back, together with just a value that Widget has a constructor for.
Here we can see that the first emplace_back leads to the same invocations of Widget's special member functions as push_back. Both first create a temporary Widget by calling the constructor, taking an int. After that, both move this freshly created temporary object into v and finally destroy the now moved-from temporary object. Yes, I know, we still moved the data, so it looks perfect.
But, look at the second invocation of emplace_back, the one from D. All we see here is the call to the constructor taking an int of Widget. No additional move, no destructor call. Why? Because we did not create an intermediated temporary object.
The purpose of emplace_back is to construct an object in place. Whenever you see the containers type in an emplace_back call, this code is simply wrong. Either you can then use push_back, or you should get rid of the temporary object.
There is more. Some people sometimes tell me that B and C aren't that bad because the compiler optimizes things away. Well, optimizations are great and good, but not relying on optimization is even better. Say we have a std::vector. The internal implementation of std::string is not just a pointer and a length. The std::string comes with some additional bytes for the Small String Optimization, something around 16 bytes. These bytes must be copied in case of push_back and even the emplace_back attempt in C. Because despite that, we see a call to Widget(Widget&&) in our output, this doesn't mean that all the data in Widget is moveable. In the case of std::string, we have some non-moveable data. Be aware of that.
Hello! I'm Andreas Fertig, a C++ trainer, and developer. I enjoy exploring the depth of the language and sharing my knowledge. Check out my training classes. Furthermore, I'm the creator of
cppinsights.io.
This is the place where I share my thoughts and announce my public talks and training classes.
To some degree we can say the task of using software for compensating miniaturisation was successful. Starting with Nokia Lumia phones and continuing with modern iPhones, image quality became acceptable and in some cases even pretty good. Modern phones offer advanced and automatic HDR, multiple shooting modes, the chance of saving in RAW, a plethora of apps for doing sophisticated shooting and editing on the go and, of course, extreme ease of sharing. So, what is the role of compact cameras today?
This post will be focusing on two major actors of this confrontation: the iPhone and the Ricoh GR II. One is the most popular camera smartphone, the other one is the most acclaimed digital pocket camera today, together with the Sony RX100 line. I think most of the considerations will also be valid for other phones and cameras bands and models.
In the end I tried shooting the GR the way I usually shoot it, that is, mostly at f2.8 and sometimes at f4, following the principle that this is not a scientific lab test but more like a report based on direct experience.
And we are not talking of being pixel peepers: an iPhone screen is smaller than a 15*10cm photo print, that is as small as you would probably print. So you must zoom in or watch it enlarged if you want to enjoy the photo at the same magnification level of a small printed photo.
For this reason, in this article I am focusing on jpg photos, because shooting only RAW would stop the comparison here: the RAW files coming out of the APS-C sensor in the GR are orders of magnitude better than the ones coming out of the iPhone small sensor and lens, and with proper post processing we can make them crush whatever the iPhone can hope to produce in RAW without its software wizardry.
This is something to consider. With extreme low light, the only way to shoot the GR is in RAW and using some software like DXO PureRaw for improving the quality before editing. And results could still be disappointing.
But what if we have enough light? Well, then things are also quite different. In this post I am including many photos, and even if they are resized they can still illustrate the reality behind this comparison. When necessary I am posting full size details.
Shooting with the iPhone and the GR seems on paper quite a similar experience: we are using a big screen for framing, we have autofocus, we can shoot a photo with one hand. But this is not telling us the whole story.
The iPhone on the contrary requires us to mostly use two hands for holding and operating the touch screen, and there are no useful physical controls. We can set the volume key as shutter but it has no half way state and using it can create camera shake that is not present if using the onscreen shutter. The old Lumias did much better, with their real two states dedicated shutter button.
The autofocus on the iPhone is much better than the one in the GR. It sticks to objects, it recognises subjects like people, animals, faces. The autofocus on the GR II is slower and it offers basic face recognition only when we shoot in full auto. I only shoot my GR in center focus, so I do focus and recompose.
One thing to keep in mind when talking of autofocus is that the small sensor on the iPhone has a huge depth of field, while the large APS-C sensor of the GR has much less. This means that the autofocus on the iPhone has a much larger tolerance for missed focus, and this (together with the lower resolution output) contributes to the feeling of dealing with a magic autofocus that never misses a shot.
On the GR we have better focus planes separation, even if you should not expect too much: in the end we are talking of an APS-C sensor mounting a 18mm lens f2.8 (equivalent to 28mm on Full Frame). But it still much, much better than the iPhone.
The GR on the contrary is a real camera, meaning that it tries to capture visible reality according to its own limitations. It is a proper tool for capturing light and there is no advanced software interfering and altering reality. Yes you can use filters but that is optional and something else entirely, it is a matter of stylistic choices, something that can also be applied with iPhone. I can shoot Positive Film with the GR or I can apply some RNI filter to the iPhone photo after I shot it, and that is just a possibility.
There are also times when we want to capture reality as it is. When we want to have a much higher image quality. When we want to shoot with a comfortable one hand grip. When we want to use flashes. When we want to capture important moments and make sure they will look great in bigger screens, or printed, and so on. In these situations, the GR makes much more sense.
Smartphones approach to photography depends on their makers and how they see photography. Right now they see it as a way for feeding social media and giving instant gratification to users. There is no care for photography as a way for preserving real memories.
Will this change? Hard to say. Software will always be necessary for overcoming miniaturization, and even if it will be tuned to being more respectful of reality, it will still be a software interpretation nonetheless.
Since the small sensors and optics will not be enough, AI will step in and fix the issues by creating data that is simply not existing or with an unacceptable signal to noise ratio. I am not particularly enthusiastic about this future.
Some are thinking that cameras will survive only if they embrace AI and software, but I think it is the opposite: cameras can only stay meaningful and relevant if they offer a practical and high quality way for capturing reality as it is, in the most faithful way, without poisoning the images with artificial data and software interpretation.
Cameras are already doing their best for capturing reality as it is, so if this is important for you, they still are a better choice than a smartphone. No matter how old or limited a compact digital camera is, it will still tell you more truth than a smartphone.
Thank you very much Ian! The original text was longer but I did cut the part about video. I may add it back at some point, and I also want to add more photo examples and text about portraiture, because it is an interesting topic. I will send a newsletter after I update it!
Hello Gerardo! Or Gerardi ? ? I am glad you like the blog! The LightPix offers a very different experience compared to the GR II in-camera flash. The LightPix is more powerful, it can use small colored filters that allow for creative solutions, and most importantly it can be used off camera, so you can actually create nice volume rendering on the go, especially for portraits. I guess the next post could be about GR II + LightPix flash! I have no particular recipes, my camera setting are mostly the same I described in the GR II review, and I usually keep white balance on daylight so that all photos have the same wb and I get warmer tones in portrais. Thanks for reading and commenting!
Hello Andrea, a really useful comparison between smartphone and camera. Thanks a lot for this detailed description. I am using digital cameras since 2001, full format since 2008 and a compact digital cam since 2016. All what you said isthe truth, twice and thee or four times.
I do not like digital manipulation of pictures. As a journalist I do not manipulate pictures (only brightness and contrast as we already did with analogue film) and I think what iphones or android phones do is changing reality.
Thank you very much for your detailed insights.
Thomas
3a8082e126