C++ Logo


Advanced search

Re: [std-proposals] 128-bit integers

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 11 Feb 2024 09:36:12 -0800
On Sunday, 11 February 2024 04:43:55 PST Nikolay Mihaylov via Std-Proposals
> std::to_string(std::int128_t) - this can not be done, because uint128_t
> may happen to "hold" a number bigger than size_t.
> such big number is not "addressable", e.g. you can not make an array with
> more than size_t elements - this sounds strange, but on 32 bit machine, if
> you do array of UINT32_MAX (not sure of correct definition in C),
> then if the array is from 1 byte elements, it will "eat" all your memory.

The maximum single-object size is SIZE_MAX.

The maximum array size is limited to PTRDIFF_MAX, which means it can have at
most PTRDIFF_MAX-1 elements. Since every array and object can be cast to a
byte type, then it stands to reason the maximum object size is

        std::min(PTRDIFF_MAX - 1, SIZE_MAX)

On all current, modern platforms, ptrdiff_t and size_t are integers of the same
size, therefore the constraining maximum size is actually PTRDIFF_MAX - 1.

There is exactly one container instantiation in the standard library that can
support more than PTRDIFF_MAX - 1 elements, even in theory, in current modern
architectures. It's not std::vector<byte type>.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2024-02-11 17:36:14