220 34960 <6d0ad98b-87d5-43dd-ac54-2b7d3e03e31b@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Aleksey Loginov <aleksey.loginov@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Idea about "std::pmr::memory_resource"
Date: Mon, 16 Oct 2017 03:55:41 -0700 (PDT)
Lines: 240
Approved: news@gmane.org
Message-ID: <6d0ad98b-87d5-43dd-ac54-2b7d3e03e31b@isocpp.org>
References: <0a8293b4-3246-47a5-9881-bc1ca4b91772@isocpp.org>
 <07ddb1f6-d3af-43df-bf96-8975c1ab4313@isocpp.org>
 <2e191a96-1952-479b-b78b-22e31f8e03de@isocpp.org>
 <0e37b5ae-64f6-4a8a-86bd-f44b119ed40a@isocpp.org>
 <15f8c5ba-3a6a-4441-9620-92e157c66094@isocpp.org>
 <26fe4cb4-98ca-41cc-ac96-5c51851799d1@isocpp.org>
 <fee0a310-5dc5-4421-bf49-bc8fa164fe29@isocpp.org>
 <784ffce8-ace7-449d-a13d-a99d7336117a@isocpp.org>
 <d029c18a-12ee-4a7d-828c-ab1bd07b58c6@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_7060_1982514003.1508151341153"
X-Trace: blaine.gmane.org 1508151354 30224 195.159.176.226 (16 Oct 2017 10:55:54 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 16 Oct 2017 10:55:54 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCGIDMXA5AJRBLNASLHQKGQEAZAZ4NI@isocpp.org Mon Oct 16 12:55:49 2017
Return-path: <std-proposals+bncBCGIDMXA5AJRBLNASLHQKGQEAZAZ4NI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk0-f71.google.com ([209.85.213.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCGIDMXA5AJRBLNASLHQKGQEAZAZ4NI@isocpp.org>)
	id 1e433Y-0005g3-4U
	for gclcip-std-proposals@m.gmane.org; Mon, 16 Oct 2017 12:55:36 +0200
Original-Received: by mail-vk0-f71.google.com with SMTP id c76sf5951025vkd.14
        for <gclcip-std-proposals@m.gmane.org>; Mon, 16 Oct 2017 03:55:43 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=eI0Bm2Q7AX3EKSp4U4mz2OYXL5eUfILeSm6xVCbCtFA=;
        b=QyG1Tz6X01vEmcn84psAUfKv7aso/q3jvuGgwNg+ag1Y+ORyofcFWG7TrzG330wx7f
         bWGwv/i3jUPa7Zy78I33ettyOOCagUY8mfmpWnRI+6QY2zAkn7dIFFofM4+Mth5mXh2R
         PazF4AjsbrtD/v8y+TsUoQOf9V8beaz3g+D7r4NI9LPqYO4G/4TzqOu9u6nhMEYI5Z6l
         0b5TAqcXNjK5O4Ty6RBT6SauVXJYJArdbfnxw0FVF5FuemiwVKgvbRa0mlKOadJzw81Y
         0ESqv4jT12wVsmGWbjTU61+kCk0NpfblVeSdViu4kEcQAEWbh62e3O9rlQKt5e2Uihly
         IHHQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=eI0Bm2Q7AX3EKSp4U4mz2OYXL5eUfILeSm6xVCbCtFA=;
        b=XLn94NpIOCpbEEbDpDBWYIo8bD8+m+BWVE98SapktQhzuDzpIhNPUbkwj+Jp8dGCte
         HxFXJ48v2rSldDk7KYVAjCJQ9ks6b5hnPx7xPVzfrrZfbha5CW0gfbrutV5CqBU41Upo
         CM2SHY/aWx2vHEGUywxlfc6NOAzNh2GYSJ/pxT2HTqj7bkZMVaYjDcX40GBeF7Un9qoQ
         m61ZeAT3ug7tacEPGDXBipsL+jrVZVNEOwVlj6RBo369zQceUFuEMv7UpkJjDTlW6JaP
         3CC2zfxd1k2U46hv9D5St/VOXNPftKV7a5u9V2o0KuoMfQ2S5JoXWCNEnEG8T8/HxCia
         3kxA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=eI0Bm2Q7AX3EKSp4U4mz2OYXL5eUfILeSm6xVCbCtFA=;
        b=FFNPq23sWnVCuy8Dncu8+x8d3F5Sqm1yuMrBjGf1IZlRnfB5NcRHVQBkoysXLVp79a
         8MbXfMWRfF1uHVG6i6LLoheU9yz1OKuZ0dmJk1wAfzfTFnLkypc1kJ00rSLcJEGmocAJ
         S4UmwGWYMvB1szkHRHd1tHJPLuAScQ40KIbufDCDMzSlOPaJpJPJiTbmTcb5IUNZjTCh
         4sxjLIDCsatMowyeB9RW2oxSrZiDMcW8YvWebvHO6UXNWBVb7qheoPoqvjwmC50rGCrJ
         5h+ryNFBEafEZKcuiZg/eH5Jfo74BZ7aN6zYPpCs0mkCiEndddD/OKlOqHMlmq7vfk8k
         QWhQ==
X-Gm-Message-State: AMCzsaUd0SYbZ+9EuRocUt3NLlMuJPQdp7wsG0b/zE6P4oaI8xBVxt/p
	6r/KAd9inUjA46ybsuTVq5vHuw==
X-Google-Smtp-Source: AOwi7QATUGzzj/jO7rspuRO9coaShVr+NmPRV8sLytNGQ4Tk5zT1b3qQjAABlj7VUKB45mDx8ea6ng==
X-Received: by 10.31.10.67 with SMTP id 64mr4836660vkk.17.1508151343370;
        Mon, 16 Oct 2017 03:55:43 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.31.132.145 with SMTP id g139ls1176822vkd.2.gmail; Mon, 16 Oct
 2017 03:55:41 -0700 (PDT)
X-Received: by 10.31.50.18 with SMTP id y18mr97539vky.6.1508151341711;
        Mon, 16 Oct 2017 03:55:41 -0700 (PDT)
In-Reply-To: <d029c18a-12ee-4a7d-828c-ab1bd07b58c6@isocpp.org>
X-Original-Sender: Aleksey.Loginov@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: <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:34960
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/34960>

------=_Part_7060_1982514003.1508151341153
Content-Type: multipart/alternative; 
	boundary="----=_Part_7061_333586511.1508151341153"

------=_Part_7061_333586511.1508151341153
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable



=D0=BF=D0=BE=D0=BD=D0=B5=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA, 16 =D0=
=BE=D0=BA=D1=82=D1=8F=D0=B1=D1=80=D1=8F 2017 =D0=B3., 13:26:09 UTC+3 =D0=BF=
=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Mingxin =
Wang=20
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>
> On Monday, October 16, 2017 at 6:37:17 AM UTC+8, Nicol Bolas wrote:
>>
>> On Sunday, October 15, 2017 at 1:05:37 PM UTC-4, Mingxin Wang wrote:
>>>
>>> On Sunday, October 15, 2017 at 11:12:03 PM UTC+8, Nicol Bolas wrote:
>>>
>> I also oppose "MemoryResource" to be added to the constructor of a type=
=20
>>> erased facility; instead, I think it would be a good idea to add it to =
the=20
>>> class template, e.g.,
>>>
>>> template <class T, class MR>
>>> class function; // undefined
>>>
>>> template <class R, class... Args, class MR>
>>> class function<R(Args...), MR> { ... };
>>>
>>>
>> Why would we want this? This creates interoperation difficulty, since=20
>> `function<Prototype, Allocator1>` is a different type from=20
>> `function<Prototype, Allocator2>`. Passing them around becomes problemat=
ic.
>>
>> I don't disagree with the idea of having allocation control over=20
>> type-erased objects like `function`. But making it a template parameter =
is=20
>> just not a good solution to this problem. `function` and `any` are=20
>> polymorphic types; invoking any of their common operations like copying =
or=20
>> function calling or value extraction requires the equivalent of virtual=
=20
>> overhead. Considering that they already have such overhead, what's wrong=
=20
>> with having their allocator have such overhead?
>>
>
> Adding a "MemoryResource" type to the template of a polymorphic facility=
=20
> is positive for performance in large-scale programming. Providing there i=
s=20
> a class template `my_any` that has the same functionality as `std::any`=
=20
> does, except that users are allowed to specify a "MemoryResource" type to=
=20
> `my_any`:
>
> template <class MR =3D default_memory_resource>
> class my_any;
>
> Users are able to configure the class to optimize performance. For=20
> example, in a high-concurrency environment, users may choose pooled memor=
y=20
> as the memory resource to avoid contention:
>
> using pooled_any =3D my_any<synchronized_memory_resource>;
>
> If there is no particular consideration in performance, it is also allowe=
d=20
> to use the default memory resource, e.g. `my_any<>`.
>
=20
Let's look at a more applied example:

template<size_t Size>=20
struct static_resource : memory_resource { aligned_storage_t<Size> m_data;=
=20
};

template<typename MR>
struct my_any;


my_any<default_memory_resource> x1;
my_any<static_resource<32>> x2;

x1 =3D 1;
x2 =3D x1;

assert(x2 =3D=3D 1);


How can you do this without RTTI?

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/6d0ad98b-87d5-43dd-ac54-2b7d3e03e31b%40isocpp.or=
g.

------=_Part_7061_333586511.1508151341153
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>=D0=BF=D0=BE=D0=BD=D0=B5=D0=B4=D0=B5=D0=BB=D1=8C=
=D0=BD=D0=B8=D0=BA, 16 =D0=BE=D0=BA=D1=82=D1=8F=D0=B1=D1=80=D1=8F 2017 =D0=
=B3., 13:26:09 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=
=D0=B5=D0=BB=D1=8C Mingxin Wang =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Monday, Oc=
tober 16, 2017 at 6:37:17 AM UTC+8, Nicol Bolas wrote:<blockquote class=3D"=
gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid=
;padding-left:1ex"><div dir=3D"ltr">On Sunday, October 15, 2017 at 1:05:37 =
PM UTC-4, Mingxin Wang wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div d=
ir=3D"ltr">On Sunday, October 15, 2017 at 11:12:03 PM UTC+8, Nicol Bolas wr=
ote:</div></blockquote><div></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"=
><div dir=3D"ltr"><div><div></div><div>I also oppose &quot;MemoryResource&q=
uot; to be added to the constructor of a type erased facility; instead, I t=
hink it would be a good idea to add it to the class template, e.g.,</div><d=
iv><br></div><div><div style=3D"background-color:rgb(250,250,250);border-co=
lor:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-wo=
rd"><code><div><font color=3D"#660066"><div><div>template &lt;class T, clas=
s MR&gt;</div><div>class function; // undefined</div><div><br></div><div>te=
mplate &lt;class R, class... Args, class MR&gt;</div><div>class function&lt=
;R(Args...), MR&gt; { ... };</div></div></font></div></code></div></div><di=
v><br></div></div></div></blockquote><div><br></div><div>Why would we want =
this? This creates interoperation difficulty, since `function&lt;Prototype,=
 Allocator1&gt;` is a different type from `function&lt;Prototype, Allocator=
2&gt;`. Passing them around becomes problematic.</div><div><br></div><div>I=
 don&#39;t disagree with the idea of having allocation control over type-er=
ased objects like `function`. But making it a template parameter is just no=
t a good solution to this problem. `function` and `any` are polymorphic typ=
es; invoking any of their common operations like copying or function callin=
g or value extraction requires the equivalent of virtual overhead. Consider=
ing that they already have such overhead, what&#39;s wrong with having thei=
r allocator have such overhead?</div></div></blockquote><div><br></div><div=
>Adding a &quot;MemoryResource&quot; type to the template of a polymorphic =
facility is positive for performance in large-scale programming. Providing =
there is a class template `my_any` that has the same=C2=A0functionality as =
`std::any` does, except that users are allowed to specify a &quot;MemoryRes=
ource&quot; type to `my_any`:</div><div><br></div><div><div style=3D"backgr=
ound-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:soli=
d;border-width:1px;word-wrap:break-word"><code><div><div><div>template &lt;=
class MR =3D default_memory_resource&gt;</div><div>class my_any;</div></div=
></div></code></div><br>Users are able to configure the class to optimize p=
erformance. For example, in a high-concurrency environment, users may choos=
e pooled memory as the memory resource to avoid contention:</div><div><br><=
/div><div><div style=3D"background-color:rgb(250,250,250);border-color:rgb(=
187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><cod=
e><div><font color=3D"#660066">using pooled_any =3D my_any&lt;synchronized_=
memory_<wbr>resource&gt;;</font><br></div></code></div><br>If there is no p=
articular consideration in performance, it is also allowed to use the defau=
lt memory resource, e.g. `my_any&lt;&gt;`.</div><div></div></div></blockquo=
te><div>=C2=A0</div><div>Let&#39;s look at a more applied example:</div><di=
v><br></div><div><div class=3D"prettyprint" style=3D"background-color: rgb(=
250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bord=
er-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">template</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">siz=
e_t </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Size</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> <br></span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> static_resource </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: rgb(34, 34, 34);"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">memory_resource </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span></span><span style=3D"color: rgb(0, 0, 0); font-family: DejaVuSansM=
ono, &quot;DejaVu Sans Mono&quot;, courier, monospace; font-size: 12.8px; w=
hite-space: nowrap; background-color: rgb(255, 255, 255);"><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">aligned_storage_t</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span></span><span st=
yle=3D"color: rgb(102, 0, 102); font-family: Arial, Helvetica, sans-serif;"=
>Size</span><span style=3D"color: rgb(0, 0, 0); font-family: DejaVuSansMono=
, &quot;DejaVu Sans Mono&quot;, courier, monospace; font-size: 12.8px; whit=
e-space: nowrap; background-color: rgb(255, 255, 255);"><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&gt;</span></span><span style=3D"fon=
t-family: Arial, Helvetica, sans-serif;"><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> m_data</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">};</span></span></div><div class=3D"subprettyprint"><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">template</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">&lt;</span><span style=3D"" class=3D"styled-b=
y-prettify"><font color=3D"#000000">typename MR</font></span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">=C2=A0my_any;<br><br><br>my_any&lt;default_</sp=
an><span style=3D"color: rgb(0, 0, 0);">memory_resource</span><span style=
=3D"color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif;">&gt; x=
1;</span></div><div class=3D"subprettyprint"><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><span class=3D"styled-by-prettify">my_any&lt;</=
span><span style=3D"font-family: Arial, Helvetica, sans-serif;">static_reso=
urce&lt;32&gt;</span><span style=3D"font-family: Arial, Helvetica, sans-ser=
if;">&gt; x2;</span><br><br><span style=3D"font-family: Arial, Helvetica, s=
ans-serif;">x1 =3D 1;<br>x2 =3D x1;<br></span><br>assert(</span><span style=
=3D"color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif;">x2 =3D=
=3D 1</span><span style=3D"color: rgb(0, 0, 0); font-family: Arial, Helveti=
ca, sans-serif;">);</span></div><div class=3D"subprettyprint"><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v><br></div><div>How can you=C2=A0do this without RTTI?</div><div><br></div=
></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/6d0ad98b-87d5-43dd-ac54-2b7d3e03e31b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6d0ad98b-87d5-43dd-ac54-2b7d3e03e31b=
%40isocpp.org</a>.<br />

------=_Part_7061_333586511.1508151341153--

------=_Part_7060_1982514003.1508151341153--

.
