C++ Logo

std-discussion

Advanced search

Re: Segmentation Fault with stack top access.

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 11 Oct 2021 15:01:00 -0400
On Mon, Oct 11, 2021 at 1:59 PM Gennaro Prota via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
>
>
>
> On Mon, Oct 11, 2021, 08:54 Anubhav Guleria via Std-Discussion <std-discussion_at_[hidden]> wrote:
>>
>> Thanks for clarifying.
>>
>> Any specific reason why container's pop_back method can't check for
>> current size and if it is 0 then make the pop operation a no-op?
>
>
> You'll find that C and C++ people are, with very few exceptions, fixated with micro-optimizations (a known anti-pattern).

Point of order:

Micro-optimization as an anti-pattern is only a legitimate argument
when you're talking about an application *as a whole* (or at the very
least, large-scale systems that have relatively minimal interaction
with the outside world). If you're writing an application, you should
concern yourself with the application's performance as a whole.

Libraries are a different story, *especially* low-level utility
libraries. Such libraries have two properties that matter in this
context: they solve very specific problems, and if they cause a
performance issue in the application that uses it, the maker of that
application *cannot fix it*.

When you're writing a piece of software for a specific purpose within
a specific application, avoiding micro-optimizations makes sense. When
you're writing a tool for other people to use, and you cannot predict
which performance issues matter to which ones of your users, then you
need to *assume* that these optimizations matter. Because if you don't
make that assumption, and you're *wrong* for a particular user... they
can't fix the problem *you* created.

Not without ditching your library and building their own. Which means
that your library failed at its job.

It's the difference between worrying about the weight of a hammer and
worrying about the weight of the shovel at the end of the excavator. A
few grams of weight on a hammer can matter a lot for how many times
you can swing it before it gets tiring. But a few grams in a shovel is
irrelevant to the fuel performance of an excavator.

Makers of low-level tools need to think about things that makers of
high-level tools don't. And vice-versa. It is a mistake to apply rules
meant for one use case to the other.

Received on 2021-10-11 14:01:14