Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Behavior for out-of-memory

44 views
Skip to first unread message

Ian Collins

unread,
Apr 6, 2017, 8:41:54 PM4/6/17
to
On 04/ 7/17 12:34 PM, Stefan Ram wrote:
> It is conceivably, that when a vector is allocated or the
> »push_back« member function is called, (dynamic) memory is
> missing to accomplish the intention of that call.
>
> Where does the standard specify behavior for this?
>
> In 17.5.5.12p4 (was: 17.6.5.12p4) there is a sentence saying:
>
> »Any other functions defined in the C++ standard library
> that do not have an exception-specification may throw
> implementation-defined exceptions unless otherwise specified.«
>
> This should allow to throw an exception in the case of
> missing memory. But is this the most specific sentence
> about the behavior of »push_back« (and similar functions)
> in the case of lack of (dynamic) memory in the standard?

By implication (push_back may call new), throwing std::bad_alloc.

--
Ian

Vir Campestris

unread,
Apr 10, 2017, 4:07:00 PM4/10/17
to
On 07/04/2017 14:07, Stefan Ram wrote:
> Found this:
>
> 20.10.9 The default allocator [default.allocator]
> ....
> 20.10.9.1 allocator members [allocator.members]
> ....
> T* allocate(size_t n);
> ....
> 4 Throws: bad_alloc if the storage cannot be obtained.

Except of course Linux will say "Yes, you can have a gigabyte". Then
fail at page fault time. I don't think apps can cope with that.

AIUI you can turn overcommit off. Its mere existence tells us how small
a problem true out-of-memory is on desktop class and above.

Andy
0 new messages