220 35060 <2688395.4cN1N1XxoH@tjmaciei-mobl1> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: std::vector, std::string attach/detach
 external buffer
Date: Fri, 20 Oct 2017 13:12:13 -0700
Lines: 36
Approved: news@gmane.org
Message-ID: <2688395.4cN1N1XxoH@tjmaciei-mobl1>
References: <f7b8bf44-80f9-4675-94b2-c876a353bd02@isocpp.org> <CAFk2RUZBM-5bnr9+xUsDBk43P0xZqXR5b0VEEjovnSkixpxzKA@mail.gmail.com> <e3cb95dd-f26d-459d-aa3f-a9bc1cc23d3d@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: blaine.gmane.org 1508530351 24708 195.159.176.226 (20 Oct 2017 20:12:31 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 20 Oct 2017 20:12:31 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBJNRVHHQKGQERCTE5CY@isocpp.org Fri Oct 20 22:12:25 2017
Return-path: <std-proposals+bncBCB4TK757YBRBJNRVHHQKGQERCTE5CY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wr0-f197.google.com ([209.85.128.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRBJNRVHHQKGQERCTE5CY@isocpp.org>)
	id 1e5deR-0004NZ-2I
	for gclcip-std-proposals@m.gmane.org; Fri, 20 Oct 2017 22:12:15 +0200
Original-Received: by mail-wr0-f197.google.com with SMTP id k15sf6252327wrc.1
        for <gclcip-std-proposals@m.gmane.org>; Fri, 20 Oct 2017 13:12:22 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1508530342; cv=pass;
        d=google.com; s=arc-20160816;
        b=JTx/IthAInUtNRGBH/qB6HACXrKgGwPKaaLUSSNuSKIbixo+KC7tWxGIpxIQnL/9xV
         7iFSoXDuVHJMg5LqXZndoUrOrqPB6QLndDF22XdAS1LX3HVCwYzQdlcm206ZgV26bvoX
         764T2HruzPzvk55it/wVWtAasATlqJlsvw0V3KPaT5VLolnyA8gjes6uNZuRjLQTS6Sn
         1WtPP0x5ROLqtGy7DqmLIjawDEH7z54PhR26jUDsEdbwPgXZXcOvLtDr4Z04G4DJhG4i
         SS6zND4qVlpZc+XfTd6HQ7XhMzp9EepYbJd3RTdWXh6kOwJpKbb4hZO/Qu6ifVDqDoEg
         FTJg==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:mime-version:references
         :in-reply-to:message-id:date:subject:to:from
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=Ysbww0Dj+nJsBfB4u7KMa8rxTVygQBXYG4WNE8QNpcE=;
        b=bqaKAoNtNViY4NR/haOBTruAk4rGSmJU0gwCHOjUuOmxBB62VUrFfVGjxvhVVUfzt0
         jWvHxexgaT8npwkOpBFfO4kOff3ugUaAXaJIEaR7lEWCCuZp0HuQBfI2+uATaUe1RAf0
         qMQad+knpC8UK5vyxg7LKk5wZ//+2/pvpgghLABUlIcspHwnmOkrykZ6mFSww2TcSPfy
         ENL5/TZP4mrrTCsVVWW3L6CTwTFQ7YXSlUdyGNYnaSSRp8+tjoQNG/TZdFnElgYtxs0p
         5z0npUYI7IC4i7IYcHiDIqC8VZnE+YRCakxDYuUNsXkpmVTzhCT5sV3KZHtGid6ggB/M
         2rZw==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mailfrom=thiago@macieira.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:to:subject:date:message-id:in-reply-to:references:mime-version
         :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=Ysbww0Dj+nJsBfB4u7KMa8rxTVygQBXYG4WNE8QNpcE=;
        b=tasX7BZm0XBhZxm4AyUEjzfGP6uhKXRFKoz3U2XvLMB34GUFOcC9hi//rOO5/M4ZCX
         6rB6uPh/kITIh748i4m0XatlfEyZIIznAGmk0Or+uLsxBEqFrmfnrw643y42YekYNY5d
         YmNZavrsqfEqgEx5BeKRmvCAKdTyFw5GqHXf9lUv6nnVT6UY0CC6Ss3vO8tj3m8fqSaG
         oOBmSqzLCxSMMX2VDmkYRaEzN5v+LdRD9mClvL5GO0xC3be0FeNaJgPVOutMwPS2RUmg
         ijSs8XIeBO8UQtmHuWp3dsx9h2naOlDbKYbvVif8gOkRt/FXTqV4rLXWMYOr9KF3ZSiY
         rqsg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references:mime-version:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=Ysbww0Dj+nJsBfB4u7KMa8rxTVygQBXYG4WNE8QNpcE=;
        b=G4hlDgn/oNdaf/k9Ykrk7OZTypsCqsKNUJP7fBtasiegbYhohUHGs+HY0HMi40mDmX
         HtX8p+VyHjvZnVJM/Ua5y3TWFmUW54bxvVmY2oOCHdvWbkfUkARSOAQyD3AD1g1Ym6qP
         umjUv6QdRmXW0xGOFPXLECsmw20y9Pwu6nL9tna5zcGxVWCLSNo68OmAgr4NIg9tSsNd
         /M9pI5JBxcQTz3BMFnLm7fK4VGwIn3mBpeak1/4Akpxr/lH5G1y8bkmHMkTqDv87XQQE
         HNAp1LwhS8ZBSRqS/R3B/UfuV23DR0nYILPJMrpMqv/q+uYglR1Gx28ln91Nzx/tnok7
         nN6w==
X-Gm-Message-State: AMCzsaU4M9k8ufWrvvGxDHriPQi4xs0QMW/HcMmwNqqt0rEs0ww1UaRc
	Ej+rBObQ/36Vk+T4h0jfvXhxrg==
X-Google-Smtp-Source: ABhQp+TEkeMZBcTRIlwV1CBI5RpbbEKlvLvbmyTO6fV6ILyIjMYKnLYfNGDVBIbaxTBadVRY85fPHg==
X-Received: by 10.28.63.130 with SMTP id m124mr2537wma.20.1508530342603;
        Fri, 20 Oct 2017 13:12:22 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.218.73 with SMTP id r70ls469780wmg.2.gmail; Fri, 20 Oct
 2017 13:12:21 -0700 (PDT)
X-Received: by 10.28.232.75 with SMTP id f72mr20708wmh.90.1508530341404;
        Fri, 20 Oct 2017 13:12:21 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1508530341; cv=none;
        d=google.com; s=arc-20160816;
        b=ZFOO/xI8Iv/s1CudVKTKgtuK6TNvpI+w7B0j+1dkZFYZn0xsVMMfLTh94XX5IoMBPa
         Roc1jZ7g2QU6VS5zkxZrcnoIRK+HPGK7clqwDUwxB97n3mwvpBf1ZisDC4wwIEBg+piV
         qK3MLB8mvnHHVgFoaPOl0+QetKDFhJuJcBc5ML3RFE75tgbyPMc+ItDRI9Mme89Vxn8m
         2M6GeKr1Jk5c3wvaGQ5Ja8B3vHDp7PnX5cm2cJ/Z2h0km8cqM/QWKNCDYrI+gFIo7UPV
         Ary1O+2aID9HRiLyAc8bmy5uO0wM68IWATvXzDUyInDR8cKcXPhtfHiRC4W+FflqyzCM
         bDvg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:to:from:arc-authentication-results;
        bh=nYiI6ybOrMscd/d6UqnhizHHqiuDVbvVgUg75tW427s=;
        b=RZ6U9uf6GjOXB80bzzCbDP8NdGigho9cctjCZ6alCoHUA2w6cbxTaLk2/jQRYhFmLr
         bA+F5UFmBsrfAvY07JSdRxujiGI4wY1CnwhdnSKYSOiIwg4bMgaUObPcAUpre67yvype
         SzJLTkjSQmUX5hIWQ0TQ2x9iqw5+z+aff+5XcEO6x5F7gcE3VPXYNylyWi896gBHzW1Z
         d542iO6lrdx4P50XJr1riAQvOc7eJTL5vOdGrdbHBR5q2dgtBLYhYNJ32CcBgGfGTIFV
         nrewKoX/xZrpB9sM0BeSnFyTAfo2NmrVFLIaRLVy5K1sQCozr6LatTKTjAhDkHDa/JN3
         Y4Ew==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mailfrom=thiago@macieira.org
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [78.47.120.188])
        by mx.google.com with ESMTP id h43si1326232wrh.277.2017.10.20.13.12.21
        for <std-proposals@isocpp.org>;
        Fri, 20 Oct 2017 13:12:21 -0700 (PDT)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) client-ip=78.47.120.188;
Original-Received: from tjmaciei-mobl1.localnet (jfdmzpr04-ext.jf.intel.com [134.134.139.73])
	by gondolin.macieira.info (Postfix) with ESMTPSA id 7CB5D11B4F6
	for <std-proposals@isocpp.org>; Fri, 20 Oct 2017 13:12:20 -0700 (PDT)
In-Reply-To: <e3cb95dd-f26d-459d-aa3f-a9bc1cc23d3d@isocpp.org>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mailfrom=thiago@macieira.org
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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:35060
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/35060>

On Friday, 20 October 2017 09:50:32 PDT Nicol Bolas wrote:
> The other issue is how to deal with `basic_string` and its ability to use
> small-string optimization. That is, if I have a 12-byte string and I
> initialize an SSO `string` from it, when does my buffer get deleted? The
> `basic_string` should not be required to keep my buffer around if the
> number of characters fits into the SSO buffer. So we'd have to say that the
> buffer could be deleted as recently as the call that consumes it.

Right. Once you transfer ownership to the std type, it *owns* that buffer and 
has the ability to free it as soon as it wants to.

	using cstring = std::basic_string<char, mallocator>;
	auto str = cstring::from_raw_string(someBuf, someLen);

if someLen < SSO threshold, one of two things can happen:

 1) cstring points to your buffer, despite not needing to
 2) cstring copies someBuf onto itself and frees your buffer using
    the mallocator

Note, however, the consequence:

	char *ptr = cstring.detach_buffer();

may fail.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

-- 
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 email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2688395.4cN1N1XxoH%40tjmaciei-mobl1.

.
