220 18462 <4A2E09D9-269D-4532-BC8E-DF1FD5B82BA8@gmail.com> article
Path: news.gmane.org!not-for-mail
From: Howard Hinnant <howard.hinnant@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Exposing string small string optimization size to
 avoid heap allocation.
Date: Sat, 6 Jun 2015 11:40:38 -0400
Lines: 59
Approved: news@gmane.org
Message-ID: <4A2E09D9-269D-4532-BC8E-DF1FD5B82BA8@gmail.com>
References: <19736033-58d4-441d-ae73-19804f8ef575@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\))
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1433605260 29648 80.91.229.3 (6 Jun 2015 15:41:00 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 6 Jun 2015 15:41:00 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCK2HM4L6YERB6FIZSVQKGQED2CMEII@isocpp.org Sat Jun 06 17:40:46 2015
Return-path: <std-proposals+bncBCK2HM4L6YERB6FIZSVQKGQED2CMEII@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f198.google.com ([209.85.192.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCK2HM4L6YERB6FIZSVQKGQED2CMEII@isocpp.org>)
	id 1Z1GDD-0000gq-Al
	for gclcip-std-proposals@m.gmane.org; Sat, 06 Jun 2015 17:40:43 +0200
Original-Received: by pdmx3 with SMTP id x3sf104828330pdm.1
        for <gclcip-std-proposals@m.gmane.org>; Sat, 06 Jun 2015 08:40:41 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:content-type:mime-version:subject:from
         :in-reply-to:date:content-transfer-encoding:message-id:references:to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=o8g3UoQNQGMXnTT+P0i9PjxBVILTKZzZccm4Fc9vebA=;
        b=d5U+Xvp++eCo3b6HkWopdpjIldJhlf+2o2uNbUwZT3SjhN3wNenYAa2vvkgPC8khqd
         btotPcmqxnqDHzlNCWXOJZPkAU0vNspotSWQKfTXq2LWQmi0APbns6Tu3NggGnYFNxzj
         rT3JbsWspIf2GD+YxyBmTVlI14FNKFMci/PnRB/Q/NwBiW5kwHfRcfozJDkq0CaWQFUm
         emCrC93iVMWOTg2PEy/2ZJ/EzsUwy/7jyCKs5PaF1C7A84w8eJn+8ta7qdDFWf9xYa4H
         TKg8n7D7lcZ4IJyvCRZ+gQdKEORJ+bwL5jeUzpemXsavJj9NZk8y0WbKy50JpekaJOjq
         Es1w==
X-Gm-Message-State: ALoCoQmR7xhHtXAoIoOXD9U3h3kGVpZ7yoSet8AHdoym4RZ7Ar1KbsAuEvhMi6qJcUvYPOEyj+QF
X-Received: by 10.66.149.35 with SMTP id tx3mr11018907pab.24.1433605241573;
        Sat, 06 Jun 2015 08:40:41 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.97.136 with SMTP id m8ls2041344qge.94.gmail; Sat, 06 Jun
 2015 08:40:40 -0700 (PDT)
X-Received: by 10.52.135.50 with SMTP id pp18mr15632868vdb.73.1433605240633;
        Sat, 06 Jun 2015 08:40:40 -0700 (PDT)
Original-Received: from mail-vn0-x243.google.com (mail-vn0-x243.google.com. [2607:f8b0:400c:c0f::243])
        by mx.google.com with ESMTPS id q9si18968896vds.15.2015.06.06.08.40.40
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 06 Jun 2015 08:40:40 -0700 (PDT)
Received-SPF: pass (google.com: domain of howard.hinnant@gmail.com designates 2607:f8b0:400c:c0f::243 as permitted sender) client-ip=2607:f8b0:400c:c0f::243;
Original-Received: by vnbg129 with SMTP id g129so3081454vnb.0
        for <std-proposals@isocpp.org>; Sat, 06 Jun 2015 08:40:40 -0700 (PDT)
X-Received: by 10.52.126.11 with SMTP id mu11mr15753673vdb.8.1433605240172;
        Sat, 06 Jun 2015 08:40:40 -0700 (PDT)
Original-Received: from [10.0.1.8] (cpe-104-229-168-124.twcny.res.rr.com. [104.229.168.124])
        by mx.google.com with ESMTPSA id s2sm12036758vdh.8.2015.06.06.08.40.39
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sat, 06 Jun 2015 08:40:39 -0700 (PDT)
In-Reply-To: <19736033-58d4-441d-ae73-19804f8ef575@isocpp.org>
X-Mailer: Apple Mail (2.2098)
X-Original-Sender: howard.hinnant@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of howard.hinnant@gmail.com designates 2607:f8b0:400c:c0f::243 as
 permitted sender) smtp.mail=howard.hinnant@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:18462
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/18462>


> On Jun 6, 2015, at 1:14 AM, german.diago@hubblehome.com wrote:
>=20
> Hello everyone,
>=20
> I would like to know if there would be interest in a proposal for detecti=
ng when a string allocates in the heap.
>=20
> The rationale for this is that there are environments in which heap alloc=
ations should be forbidden,
> but use of short strings can still be made, with the convenience of strin=
g functions.=20
> Embedded environments are such an example:
>=20
>=20
> A static member function (or free?) could be provided. Something like:
>=20
> //Pseudo-C++, no basic_string here to go straight to the question
> class string {
>    public:
>        static std::size_t max_stack_allocated_size();
>        static bool needs_dynamic_allocation(std::size_t sz);
> };
>=20
> Any interest in this?

If you can live without constexpr, you=E2=80=99ve already got it:

#include <iostream>
#include <string>

template <class String>
std::size_t
max_stack_allocated()
{
    String s;
    return s.capacity();
}

int
main()
{
    std::cout << max_stack_allocated<std::string>() << '\n';
    std::cout << max_stack_allocated<std::wstring>() << '\n';
}

Howard

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.
