Topic: Classifying pointers
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 10 Dec 2014 11:46:42 -0800 (PST)
Raw View
------=_Part_733_1435787625.1418240802697
Content-Type: multipart/alternative;
boundary="----=_Part_734_8872036.1418240802697"
------=_Part_734_8872036.1418240802697
Content-Type: text/plain; charset=UTF-8
It would be really nice to be able to determine whether at arbitrary
pointer points to read only global memory or local memory (heap, stack,
etc..).
Here is the motivating example:
//Returns true if p points to an address in global read only memory
bool is_rom(const void* p);
//Some class which stores strings
struct Store {
void store(string_view s) {
if(!is_rom(s.data()) {
_extra_storage.push_back(std::string(s));
s = _extra_storage.back();
}
_strings.insert(s);
}
std::unordered_set<StringView> _strings;
std::list<std::string> _extra_storage; //There are more efficient ways to
do this
};
//Examples
const char f[] = "faz";
char g[] = "gaz";
void example() {
char a[] = "bar";
const char* b = "baz";
std::string c = "saz";
assert(is_rom("Foo") == true); //string literals are global and read only
assert(is_rom(a) == false); //a decays to pointer which points to address
on the stack
assert(is_rom(b) == true); //b points to string literal which is global
assert(is_rom(c.c_str()) = false); //heap allocated
assert(is_rom(f) == true); //f decays to pointer which points to address
in read only global memory
assert(is_rom(g) == true); //g decays to pointer which points to address
in RW global memory
The motivating example here is with read only strings. The C++ runtime
allocates read-only storage for string literals so there is no reason to
make a second copy of them and store it at runtime. Store::store checks
whether the input string comes from read only global memory and if it does
just adds it to the set. If the string comes from either a user created
buffer (stack, heap, etc..), or comes from global memory which is not read
only (can be overwritten later), we make a copy and store that.
A better version of this might be to have set of different memory
classifications:
enum class memory_class {
unknown, //Unknown memory address (maybe memory mapped io, unmapped
pages, or other strange things)
stack, //Points to memory on the stack
heap, //Points to memory on the heap
static, //Points to global read/write memory
rom //Points to global read only memory (may exist within a ROM)
};
memory_class get_memory_class(const void* p);
Would such a thing even be possible to implement portably? Does anyone
think exposing this information would be a bad idea?
My major use cases involve applications which store a large amount of
read-only string data at startup. Examples include finance applications
with dictionaries of symbols and video games with resource names.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_734_8872036.1418240802697
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">It would be really nice to be able to determine whether at=
arbitrary pointer points to read only global memory or local memory (heap,=
stack, etc..).<br><br>Here is the motivating example:<br><code><br><div cl=
ass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-c=
olor: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap=
: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">//Returns true if p=
points to an address in global read only memory<br>bool</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> is_rom</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">const void</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> p</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br>//Some class which stores strings<br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
06;" class=3D"styled-by-prettify">Store</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> store</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">string_=
view s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(!</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">is_rom</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">s</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">data</span><span 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: #660;" class=3D"styled-by-prettify">{</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br> =
_extra_storage</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">push_=
back</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">string</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">s</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">));</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br> s </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> _extra_storage</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">back</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br> _strings</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">insert</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br> std</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">unordered_set</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">StringView</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> _strings</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br> std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">list</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
string</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> _extra_st=
orage</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #800;" class=3D"styled-by-prettify">//There are more effici=
ent ways to do this</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">//Examp=
les</span><span style=3D"color: #000;" class=3D"styled-by-prettify"></span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify"><br>const char f[=
] =3D "faz";<br>char g[] =3D "gaz";<br><br>void</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> example</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">char</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[]</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">"bar"</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">char</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #080;" class=3D"styled-by-prettify">"baz"</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br> std</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">string</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> c </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettif=
y">"saz"</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"></span><br><c=
ode><code class=3D"prettyprint"><span style=3D"color: #008;" class=3D"style=
d-by-prettify"> assert</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">is_rom</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"Foo=
"</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">true</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">); //string literals are global and read only<=
br> assert(is_rom(a) =3D=3D false); //a decays to pointer which point=
s to address on the stack<br> assert(is_rom(b) =3D=3D true); //b poin=
ts to string literal which is global<br> assert(is_rom(c.c_str()) =3D=
false); //heap allocated<br> assert(is_rom(f) =3D=3D true); //f deca=
ys to pointer which points to address in read only global memory</span></co=
de></code><br><code><code class=3D"prettyprint"><span style=3D"color: #660;=
" class=3D"styled-by-prettify"><code><code class=3D"prettyprint"><code><cod=
e class=3D"prettyprint"><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify"> assert(is_rom(g) =3D=3D true); //g decays to pointer which po=
ints to address in RW global memory</span></code></code></code></code></spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></co=
de></code></div></code></div><br>The motivating example here is with read o=
nly strings. The C++ runtime allocates read-only storage for string literal=
s so there is no reason to make a second copy of them and store it at runti=
me. Store::store checks whether the input string comes from read only globa=
l memory and if it does just adds it to the set. If the string comes from e=
ither a user created buffer (stack, heap, etc..), or comes from global memo=
ry which is not read only (can be overwritten later), we make a copy and st=
ore that.<br><br>A better version of this might be to have set of different=
memory classifications:<br><br><div class=3D"prettyprint" style=3D"backgro=
und-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-sty=
le: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pretty=
print"><div class=3D"subprettyprint"><span style=3D"color: #606;" class=3D"=
styled-by-prettify">enum class memory_class {<br> unknown, //Unknown =
memory address (maybe memory mapped io, unmapped pages, or other strange th=
ings)<br> stack, //Points to memory on the stack<br> heap, //Po=
ints to memory on the heap<br> static, //Points to global read/write =
memory<br> rom //Points to global read only memory (may exist within =
a ROM)<br>};<br><br>memory_class get_memory_class(const void* p);<br></span=
><span style=3D"color: #660;" class=3D"styled-by-prettify"></span></div></c=
ode></div><br>Would such a thing even be possible to implement portably? Do=
es anyone think exposing this information would be a bad idea?<br><br>My ma=
jor use cases involve applications which store a large amount of read-only =
string data at startup. Examples include finance applications with dictiona=
ries of symbols and video games with resource names.<br></code><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_734_8872036.1418240802697--
------=_Part_733_1435787625.1418240802697--
.
Author: Nevin Liber <nevin@eviloverlord.com>
Date: Wed, 10 Dec 2014 14:14:32 -0600
Raw View
--001a11c26b423269d90509e25121
Content-Type: text/plain; charset=UTF-8
On 10 December 2014 at 13:46, Matthew Fioravante <fmatthew5876@gmail.com>
wrote:
>
>
> Would such a thing even be possible to implement portably?
>
Doubtful. Think of memory mapping.
> Does anyone think exposing this information would be a bad idea?
>
Read-only is insufficient. The other (arguably more important) piece of
information you need to know is lifetime.
> My major use cases involve applications which store a large amount of
> read-only string data at startup.
>
If you have a large amount of program-lifetime read-only string data at
startup, you don't need this feature, as you already *know* that you have
program-lifetime read-only string data.
The problem comes when you want to mix data with different lifetimes. Code
which does this microoptimization on a regular basis tends to be fragile,
buggy and difficult to reason about. You are better of separating the
concerns of managing the data lifetime from usage; classes shouldn't
conditionally manage lifetime.
--
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a11c26b423269d90509e25121
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On 10 December 2014 at 13:46, Matthew Fioravante <span dir=
=3D"ltr"><<a href=3D"mailto:fmatthew5876@gmail.com" target=3D"_blank">fm=
atthew5876@gmail.com</a>></span> wrote:<br><div class=3D"gmail_extra"><d=
iv class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:=
0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><c=
ode><div><span style=3D"color:#606"><br></span><span style=3D"color:#660"><=
/span></div></code><code><br>Would such a thing even be possible to impleme=
nt portably? </code></div></blockquote><div><br></div><div>Doubtful.=C2=A0 =
Think of memory mapping.<br></div><div>=C2=A0</div><blockquote class=3D"gma=
il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr"><code>Does anyone think exposing this information w=
ould be a bad idea?<br></code></div></blockquote><div><br></div><div>Read-o=
nly is insufficient.=C2=A0 The other (arguably more important) piece of inf=
ormation you need to know is lifetime.<br></div><div>=C2=A0</div><blockquot=
e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol=
id;padding-left:1ex"><div dir=3D"ltr"><code>My major use cases involve appl=
ications which store a large amount of read-only string data at startup.</c=
ode></div></blockquote><div><br></div><div>If you have a large amount of pr=
ogram-lifetime read-only string data at startup, you don't need this fe=
ature, as you already <i>know</i> that you have program-lifetime read-only =
string data.<br><br>The problem comes when you want to mix data with differ=
ent lifetimes.=C2=A0 Code which does this microoptimization on a regular ba=
sis tends to be fragile, buggy and difficult to reason about.=C2=A0 You are=
better of separating the concerns of managing the data lifetime from usage=
; classes shouldn't conditionally manage lifetime.<br></div></div>-- <b=
r><div class=3D"gmail_signature">=C2=A0Nevin ":-)" Liber=C2=A0 &l=
t;mailto:<a href=3D"mailto:nevin@eviloverlord.com" target=3D"_blank">nevin@=
eviloverlord.com</a>>=C2=A0 (847) 691-1404</div>
</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c26b423269d90509e25121--
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Wed, 10 Dec 2014 15:18:16 -0500
Raw View
On 2014-12-10 14:46, Matthew Fioravante wrote:
> It would be really nice to be able to determine whether at arbitrary
> pointer points to read only global memory or local memory (heap, stack,
> etc..).
What about code segments of dynamically loaded libraries? These are read
only but I believe not guaranteed to be persistent, which seems to be
the main objective of your proposal. (I guess those could be a different
storage class. Not counting the stack/heap/etc. cases, I think we would
need to know if a given pointer is writable and if it resides in a
static segment e.g. of the main process executable or a dynamic segment
e.g. belonging to a dynamically loaded library that might be unloaded
again.)
--
Matthew
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 10 Dec 2014 22:21:03 +0200
Raw View
On 10 December 2014 at 22:18, Matthew Woehlke
<mw_triad@users.sourceforge.net> wrote:
> On 2014-12-10 14:46, Matthew Fioravante wrote:
>> It would be really nice to be able to determine whether at arbitrary
>> pointer points to read only global memory or local memory (heap, stack,
>> etc..).
>
> What about code segments of dynamically loaded libraries? These are read
> only but I believe not guaranteed to be persistent, which seems to be
> the main objective of your proposal. (I guess those could be a different
> storage class. Not counting the stack/heap/etc. cases, I think we would
> need to know if a given pointer is writable and if it resides in a
> static segment e.g. of the main process executable or a dynamic segment
> e.g. belonging to a dynamically loaded library that might be unloaded
> again.)
How would an implementation be able to tell such things about a pointer
through opaque translation units without incurring overhead?
What are the work-arounds? I imagine having separate wrappers for the
pointers with different classification and being careful what to initialize with
what would be a possibility, although it's certainly tedious and
doesn't provide magic.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 10 Dec 2014 12:32:56 -0800
Raw View
On Wednesday 10 December 2014 11:46:42 Matthew Fioravante wrote:
> It would be really nice to be able to determine whether at arbitrary
> pointer points to read only global memory or local memory (heap, stack,
> etc..).
Please design it so that it's possible for an implementation not to provide
any information. That is, you may have the situation in which "is writable"
returns false and "is read-only"also returns false, for the same region.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 10 Dec 2014 12:35:59 -0800 (PST)
Raw View
------=_Part_802_72843678.1418243759285
Content-Type: multipart/alternative;
boundary="----=_Part_803_1685906204.1418243759292"
------=_Part_803_1685906204.1418243759292
Content-Type: text/plain; charset=UTF-8
On Wednesday, December 10, 2014 3:15:16 PM UTC-5, Nevin ":-)" Liber wrote:
>
> On 10 December 2014 at 13:46, Matthew Fioravante <*fmatth...@gmail.com*
> <javascript:>> wrote:
>
>>
>>
>> Would such a thing even be possible to implement portably?
>>
>
> Doubtful. Think of memory mapping.
>
I think something memory mapped would need its own class such as
"temporary". A class which says this memory exists now but may go away at
anytime.
> Does anyone think exposing this information would be a bad idea?
>>
>
> Read-only is insufficient. The other (arguably more important) piece of
> information you need to know is lifetime.
>
Indeed. In my use case I want to determine whether the input string comes
from read only static lifetime memory. Basically I need an absolute
guarantee that the data will exist for the entire lifetime of the
application and never be modified.
> My major use cases involve applications which store a large amount of
>> read-only string data at startup.
>>
>
> If you have a large amount of program-lifetime read-only string data at
> startup, you don't need this feature, as you already *know* that you have
> program-lifetime read-only string data.
>
> The problem comes when you want to mix data with different lifetimes. Code
> which does this microoptimization on a regular basis tends to be fragile,
> buggy and difficult to reason about. You are better of separating the
> concerns of managing the data lifetime from usage; classes shouldn't
> conditionally manage lifetime.
>
I have a situation where most of the time the strings come from string
literals. One example of this is setting up a factory. Each class type
would have a string name which is used to instantiate that particular class
from the factory. Most of the time these would come from string literals
but in some cases the name might be constructed from other names.
std::string s = "C";
factory.register("A", A::make); //read only memory, can reference directly
factory.register("B", B::make); //read only memory, can reference directly
factory.register(s + "++", Cxx::make); //heap memory, need to make a
permanent copy
Using an undordered_map<StringView,T> has advantages over std::string
because when you do lookups with a StringView you don't murder performance
by first constructing a temporary std::string for hashing. To do this you
need to have an additional persistent data structure which can store the
actual string bytes. If your string comes from read only static memory,
then it already has a persistent location.
I admit the use case does seem like a micro memory optimization. I wonder
if such a thing might be useful for embedded systems.
On Wednesday, December 10, 2014 3:18:31 PM UTC-5, Matthew Woehlke wrote:
>
> On 2014-12-10 14:46, Matthew Fioravante wrote:
> > It would be really nice to be able to determine whether at arbitrary
> > pointer points to read only global memory or local memory (heap, stack,
> > etc..).
>
> What about code segments of dynamically loaded libraries?
I would give that a different class, such as "temporary" as mentioned
earlier.
On Wednesday, December 10, 2014 3:21:05 PM UTC-5, Ville Voutilainen wrote:
>
>
> How would an implementation be able to tell such things about a pointer
> through opaque translation units without incurring overhead?
>
This would happen at runtime, not compile time so separate translation
units are not a concern. Each call to the function would need to do a
lookup in the process memory map which could be a slow operation.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_803_1685906204.1418243759292
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><br>On Wednesday, December 10, 2014 3:15:16 PM UTC-5,=
Nevin ":-)" Liber wrote:<blockquote style=3D"margin: 0px 0px 0px 0.8ex; pa=
dding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: =
1px; border-left-style: solid;" class=3D"gmail_quote"><div dir=3D"ltr">On 1=
0 December 2014 at 13:46, Matthew Fioravante <span dir=3D"ltr"><<a onmou=
sedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'j=
avascript:';return true;" href=3D"javascript:" target=3D"_blank" gdf-obfusc=
ated-mailto=3D"P9E8X7z0mfcJ"><u><font color=3D"#000080">fmatth...@gmail.com=
</font></u></a>></span> wrote:<br><div><div class=3D"gmail_quote"><block=
quote style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-co=
lor: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"=
class=3D"gmail_quote"><div dir=3D"ltr"><code><div><span style=3D"color: rg=
b(102, 0, 102);"><br></span><span style=3D"color: rgb(102, 102, 0);"></span=
></div></code><code><br>Would such a thing even be possible to implement po=
rtably? </code></div></blockquote><div><br></div><div>Doubtful. Think of m=
emory mapping.<br></div></div></div></div></blockquote><div> </div><di=
v>I think something memory mapped would need its own class such as "tempora=
ry". A class which says this memory exists now but may go away at anytime.&=
nbsp;</div><blockquote style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1e=
x; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-le=
ft-style: solid;" class=3D"gmail_quote"><div dir=3D"ltr"><div><div class=3D=
"gmail_quote"><div></div><div> </div><blockquote style=3D"margin: 0px 0px 0=
px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-=
left-width: 1px; border-left-style: solid;" class=3D"gmail_quote"><div dir=
=3D"ltr"><code>Does anyone think exposing this information would be a bad i=
dea?<br></code></div></blockquote><div><br></div><div>Read-only is insuffic=
ient. The other (arguably more important) piece of information you need to=
know is lifetime.<br></div></div></div></div></blockquote><div> </div=
><div>Indeed. In my use case I want to determine whether the input string c=
omes from read only static lifetime memory. Basically I need an absolute gu=
arantee that the data will exist for the entire lifetime of the application=
and never be modified.</div><div> </div><blockquote style=3D"margin: =
0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204)=
; border-left-width: 1px; border-left-style: solid;" class=3D"gmail_quote">=
<div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></div><div> </div><bl=
ockquote style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left=
-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: soli=
d;" class=3D"gmail_quote"><div dir=3D"ltr"><code>My major use cases involve=
applications which store a large amount of read-only string data at startu=
p.</code></div></blockquote><div><br></div><div>If you have a large amount =
of program-lifetime read-only string data at startup, you don't need this f=
eature, as you already <i>know</i> that you have program-lifetime read-only=
string data.<br><br>The problem comes when you want to mix data with diffe=
rent lifetimes. Code which does this microoptimization on a regular basis =
tends to be fragile, buggy and difficult to reason about. You are better o=
f separating the concerns of managing the data lifetime from usage; classes=
shouldn't conditionally manage lifetime.<br></div></div></div></div></bloc=
kquote><div> </div><div>I have a situation where most of the time=
the strings come from string literals. One example of this is setting up a=
factory. Each class type would have a string name which is used to in=
stantiate that particular class from the factory. Most of the time these wo=
uld come from string literals but in some cases the name might be construct=
ed from other names.</div><div> </div><div style=3D"border: 1px solid =
rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, =
250);" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><font color=3D"#666600"><span style=3D"color: rgb(0, 0, 0);" cl=
ass=3D"styled-by-prettify">std</span><span style=3D"color: rgb(102, 102, 0)=
;" class=3D"styled-by-prettify">::</span><span style=3D"color: rgb(0, 0, 13=
6);" class=3D"styled-by-prettify">string</span><span style=3D"color: rgb(0,=
0, 0);" class=3D"styled-by-prettify"> s </span><span style=3D"color: rgb(1=
02, 102, 0);" class=3D"styled-by-prettify">=3D</span><span style=3D"color: =
rgb(0, 0, 0);" class=3D"styled-by-prettify"> </span><span style=3D"color: r=
gb(0, 136, 0);" class=3D"styled-by-prettify">"C"</span><span style=3D"color=
: rgb(102, 102, 0);" class=3D"styled-by-prettify">;</span></font><span styl=
e=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br>factory</span><=
span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">.</spa=
n><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">regis=
ter</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: rgb(0, 136, 0);" class=3D"styled-by-pret=
tify">"A"</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by=
-prettify">,</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-=
prettify"> A</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled=
-by-prettify">::</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled=
-by-prettify">make</span><span style=3D"color: rgb(102, 102, 0);" class=3D"=
styled-by-prettify">);</span><span style=3D"color: rgb(0, 0, 0);" class=3D"=
styled-by-prettify"> </span><span style=3D"color: rgb(136, 0, 0);" class=3D=
"styled-by-prettify">//read only memory, can reference directly</span><span=
style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br>factory</s=
pan><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">.=
</span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">=
register</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-=
prettify">(</span><span style=3D"color: rgb(0, 136, 0);" class=3D"styled-by=
-prettify">"B"</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: rgb(0, 0, 0);" class=3D"style=
d-by-prettify"> B</span><span style=3D"color: rgb(102, 102, 0);" class=3D"s=
tyled-by-prettify">::</span><span style=3D"color: rgb(0, 0, 0);" class=3D"s=
tyled-by-prettify">make</span><span style=3D"color: rgb(102, 102, 0);" clas=
s=3D"styled-by-prettify">);</span><span style=3D"color: rgb(0, 0, 0);" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: rgb(136, 0, 0);" cla=
ss=3D"styled-by-prettify">//read only memory, can reference directly</span>=
<span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br>facto=
ry</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-pretti=
fy">.</span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prett=
ify">register</span><span style=3D"color: rgb(102, 102, 0);" class=3D"style=
d-by-prettify">(</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled=
-by-prettify">s </span><span style=3D"color: rgb(102, 102, 0);" class=3D"st=
yled-by-prettify">+</span><span style=3D"color: rgb(0, 0, 0);" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: rgb(0, 136, 0);" class=3D"st=
yled-by-prettify">"++"</span><span style=3D"color: rgb(102, 102, 0);" class=
=3D"styled-by-prettify">,</span><span style=3D"color: rgb(0, 0, 0);" class=
=3D"styled-by-prettify"> </span><span style=3D"color: rgb(102, 0, 102);" cl=
ass=3D"styled-by-prettify">Cxx</span><span style=3D"color: rgb(102, 102, 0)=
;" class=3D"styled-by-prettify">::</span><span style=3D"color: rgb(0, 0, 0)=
;" class=3D"styled-by-prettify">make</span><span style=3D"color: rgb(102, 1=
02, 0);" class=3D"styled-by-prettify">);</span><span style=3D"color: rgb(0,=
0, 0);" class=3D"styled-by-prettify"> </span><span style=3D"color: rgb(136=
, 0, 0);" class=3D"styled-by-prettify">//heap memory, need to make a perman=
ent copy</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-pret=
tify"><br></span></div></code></div><div><br>Using an undordered_map<Str=
ingView,T> has advantages over std::string because when you do lookups w=
ith a StringView you don't murder performance by first constructing a tempo=
rary std::string for hashing. To do this you need to have an additional per=
sistent data structure which can store the actual string bytes. If your str=
ing comes from read only static memory, then it already has a persiste=
nt location.</div><div> </div><div>I admit the use case does seem like=
a micro memory optimization. I wonder if such a thing might be useful=
for embedded systems. </div><div> </div></div><div> </div><=
div><br>On Wednesday, December 10, 2014 3:18:31 PM UTC-5, Matthew Woehlke w=
rote:<blockquote style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bor=
der-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-sty=
le: solid;" class=3D"gmail_quote">On 2014-12-10 14:46, Matthew Fioravante w=
rote:<br>> It would be really nice to be able to determine whether at ar=
bitrary <br>> pointer points to read only global memory or local memory =
(heap, stack, <br>> etc..).<br><br>What about code segments of dynamical=
ly loaded libraries? </blockquote><div> </div><div>I would give that a=
different class, such as "temporary" as mentioned earlier. </div=
></div><div><br>On Wednesday, December 10, 2014 3:21:05 PM UTC-5, Ville Vou=
tilainen wrote:</div><blockquote style=3D"margin: 0px 0px 0px 0.8ex; paddin=
g-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px;=
border-left-style: solid;" class=3D"gmail_quote"><br><br>How would an impl=
ementation be able to tell such things about a pointer
<br>through opaque translation units without incurring overhead?
<br></blockquote><div> </div><div>This would happen at runtime, not co=
mpile time so separate translation units are not a concern. Each call to th=
e function would need to do a lookup in the process memory map which could =
be a slow operation.</div><div> </div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_803_1685906204.1418243759292--
------=_Part_802_72843678.1418243759285--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 10 Dec 2014 12:44:20 -0800 (PST)
Raw View
------=_Part_740_1151263839.1418244260292
Content-Type: multipart/alternative;
boundary="----=_Part_741_463682603.1418244260292"
------=_Part_741_463682603.1418244260292
Content-Type: text/plain; charset=UTF-8
On Wednesday, December 10, 2014 3:33:00 PM UTC-5, Thiago Macieira wrote:
>
> On Wednesday 10 December 2014 11:46:42 Matthew Fioravante wrote:
> > It would be really nice to be able to determine whether at arbitrary
> > pointer points to read only global memory or local memory (heap, stack,
> > etc..).
>
> Please design it so that it's possible for an implementation not to
> provide
> any information. That is, you may have the situation in which "is
> writable"
> returns false and "is read-only"also returns false, for the same region.
>
I think having one function would be best for efficiency. It could be done
with bit flags:
constexpr int is_persistent = 1; //true if the memory address will always
be valid for the entire lifetime of the application
constexpr int is_read_only = 2; //true if the contents of the memory
address will never be modified
int get_memory_class(const void* p);
A conforming implementation could always return 0.
I'm really interested to know if there are any other use cases for such a
feature.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_741_463682603.1418244260292
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br>On Wednesday, December 10, 2014 3:33:00 PM UTC-5, Thia=
go Macieira wrote:<blockquote style=3D"margin: 0px 0px 0px 0.8ex; padding-l=
eft: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; bo=
rder-left-style: solid;" class=3D"gmail_quote">On Wednesday 10 December 201=
4 11:46:42 Matthew Fioravante wrote:
<br>> It would be really nice to be able to determine whether at arbitra=
ry=20
<br>> pointer points to read only global memory or local memory (heap, s=
tack,=20
<br>> etc..).
<br>
<br>Please design it so that it's possible for an implementation not to pro=
vide=20
<br>any information. That is, you may have the situation in which "is writa=
ble"=20
<br>returns false and "is read-only"also returns false, for the same region=
..
<br>
</blockquote><div> </div><div>I think having one function would =
be best for efficiency. It could be done with bit flags:</div><div> </=
div><div><div style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: bre=
ak-word; background-color: rgb(250, 250, 250);" class=3D"prettyprint"><code=
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: =
rgb(0, 0, 136);" class=3D"styled-by-prettify">constexpr</span><span style=
=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> </span><span style=
=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">int</span><span st=
yle=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> is_persistent </=
span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"=
> </span><span style=3D"color: rgb(0, 102, 102);" class=3D"styled-by-pretti=
fy">1</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: rgb(136, 0, 0);" class=3D"styled-by-pre=
ttify">//true if the memory address will always be valid for the entire lif=
etime of the application</span><span style=3D"color: rgb(0, 0, 0);" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: rgb(0, 0, 136);" c=
lass=3D"styled-by-prettify">constexpr</span><span style=3D"color: rgb(0, 0,=
0);" class=3D"styled-by-prettify"> </span><span style=3D"color: rgb(0, 0, =
136);" class=3D"styled-by-prettify">int</span><span style=3D"color: rgb(0, =
0, 0);" class=3D"styled-by-prettify"> is_read_only </span><span style=3D"co=
lor: rgb(102, 102, 0);" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> </span><span style=
=3D"color: rgb(0, 102, 102);" class=3D"styled-by-prettify">2</span><span st=
yle=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">;</span><span=
style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> </span><span =
style=3D"color: rgb(136, 0, 0);" class=3D"styled-by-prettify">//true if the=
contents of the memory address will never be modified</span><span style=3D=
"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br><br></span><span st=
yle=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">int</span><span=
style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> get_memory_cl=
ass</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-pret=
tify">const</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-=
prettify">void</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styl=
ed-by-prettify">*</span><span style=3D"color: rgb(0, 0, 0);" class=3D"style=
d-by-prettify"> p</span><span style=3D"color: rgb(102, 102, 0);" class=3D"s=
tyled-by-prettify">);</span></div></code></div></div><div> </div><div>=
<span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify">A conform=
ing implementation could always </span><span style=3D"color: rgb(0, 0, 136)=
;" class=3D"styled-by-prettify">return</span><span style=3D"color: rgb(0, 0=
, 0);" class=3D"styled-by-prettify"> </span><span style=3D"color: rgb(0, 10=
2, 102);" class=3D"styled-by-prettify">0.</span></div><div><span style=3D"c=
olor: rgb(0, 102, 102);" class=3D"styled-by-prettify"></span> </div><d=
iv><span style=3D"color: rgb(0, 102, 102);" class=3D"styled-by-prettify">I'=
m really interested to know if there are any other use cases for such a fea=
ture.</span></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_741_463682603.1418244260292--
------=_Part_740_1151263839.1418244260292--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 10 Dec 2014 12:47:56 -0800
Raw View
On Wednesday 10 December 2014 12:44:20 Matthew Fioravante wrote:
> I'm really interested to know if there are any other use cases for such a
> feature.
If you're going to do this, I'd like to see something about virtual memory
there. With VMMs, you want to know whether the memory is:
- mapped from a file
- anonymous region (i.e., backed by swap)
- present or not (swapped out, not loaded from file -- would fault)
- private or shared
- clean or dirty
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 10 Dec 2014 12:46:03 -0800
Raw View
On Wednesday 10 December 2014 12:35:59 Matthew Fioravante wrote:
> Indeed. In my use case I want to determine whether the input string comes
> from read only static lifetime memory. Basically I need an absolute
> guarantee that the data will exist for the entire lifetime of the
> application and never be modified.
Ok, I'll give you the implementation for this on modern operating systems:
return false;
You can't get that absolute guarantee. First of all, to be sure that the
memory region stays present until the application exits, it needs to be in the
application's memory region itself, not in any loadable module or library.
After all, loadable modules can, by definition, be unloaded before the end of
the application's exit.
Second, even for read-only data coming from the application's binary, it's
still possible to make system calls like mprotect(2), make it writable, and
modify the memory region.
I believe the function implementation above will allow you to optimise your
code and do a lot of dead-code elimination.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 10 Dec 2014 12:51:22 -0800 (PST)
Raw View
------=_Part_6832_1026807613.1418244683003
Content-Type: multipart/alternative;
boundary="----=_Part_6833_376964399.1418244683003"
------=_Part_6833_376964399.1418244683003
Content-Type: text/plain; charset=UTF-8
On Wednesday, December 10, 2014 3:48:00 PM UTC-5, Thiago Macieira wrote:
>
> On Wednesday 10 December 2014 12:44:20 Matthew Fioravante wrote:
> > I'm really interested to know if there are any other use cases for such
> a
> > feature.
>
> If you're going to do this, I'd like to see something about virtual memory
> there. With VMMs, you want to know whether the memory is:
>
>
I'm not sure that makes sense to do in a cross platform way? Systems can
have a lot of variation in how they implement virtual memory (or whether or
not they implement it at all). How could we possibly come up with a set of
factors which make sense on all possible platforms?
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_6833_376964399.1418244683003
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, December 10, 2014 3:48:00 PM UTC-5, =
Thiago Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Wedne=
sday 10 December 2014 12:44:20 Matthew Fioravante wrote:
<br>> I'm really interested to know if there are any other use cases for=
such a=20
<br>> feature.
<br>
<br>If you're going to do this, I'd like to see something about virtual mem=
ory=20
<br>there. With VMMs, you want to know whether the memory is:
<br>
<br></blockquote><div><br>I'm not sure that makes sense to do in a cross pl=
atform way? Systems can have a lot of variation in how they implement virtu=
al memory (or whether or not they implement it at all). How could we possib=
ly come up with a set of factors which make sense on all possible platforms=
?<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_6833_376964399.1418244683003--
------=_Part_6832_1026807613.1418244683003--
.
Author: Myriachan <myriachan@gmail.com>
Date: Wed, 10 Dec 2014 14:04:38 -0800 (PST)
Raw View
------=_Part_720_2061518681.1418249078082
Content-Type: multipart/alternative;
boundary="----=_Part_721_443310869.1418249078082"
------=_Part_721_443310869.1418249078082
Content-Type: text/plain; charset=UTF-8
On Wednesday, December 10, 2014 12:51:23 PM UTC-8, Matthew Fioravante wrote:
>
>
> I'm not sure that makes sense to do in a cross platform way? Systems can
> have a lot of variation in how they implement virtual memory (or whether or
> not they implement it at all). How could we possibly come up with a set of
> factors which make sense on all possible platforms?
>
I don't think that it's possible to do this platform-independently, but you
can personally do this per-platform if you like. E.g. in Windows:
extern "C" IMAGE_DOS_HEADER __ImageBase;
bool IsInReadOnlySectionOfMyExe(const char *ptr)
{
const char *base = reinterpret_cast<const char *>(&__ImageBase);
if (ptr < base)
return false;
const IMAGE_NT_HEADERS *nt = reinterpret_cast<const IMAGE_NT_HEADERS *>(
base + __ImageBase.e_lfanew);
if (ptr >= base + nt->OptionalHeader.SizeOfImage)
return false;
DWORD rva = ptr - base;
if (rva < nt->OptionalHeader.SizeOfHeaders)
return true;
if (nt->FileHeader.NumberOfSections)
return false;
const IMAGE_SECTION_HEADERS *sections = IMAGE_FIRST_SECTION(nt);
const IMAGE_SECTION_HEADERS *endSections = sections + nt->FileHeader.
NumberOfSections;
for (; sections < endSections; ++sections)
{
if (sections->Characteristics & IMAGE_SCN_MEM_WRITE)
continue;
if ((rva >= sections->VirtualAddress) && (rva < sections->
VirtualAddress + sections->Misc.VirtualSize))
return true;
}
return false;
}
Standardizing this seems like the wrong approach, since it's difficult to
formally define and the implementer of STL could already do this as an
optimization in std::string if they wanted.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_721_443310869.1418249078082
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, December 10, 2014 12:51:23 PM UTC-8, Matthew=
Fioravante wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><br><div>I'm not sure that makes sense to do in a cross platform way? =
Systems can have a lot of variation in how they implement virtual memory (o=
r whether or not they implement it at all). How could we possibly come up w=
ith a set of factors which make sense on all possible platforms?<br></div><=
/div></blockquote><div><br>I don't think that it's possible to do this plat=
form-independently, but you can personally do this per-platform if you like=
.. E.g. in Windows:<br><br><div class=3D"prettyprint" style=3D"backgro=
und-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-sty=
le: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pretty=
print"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"=
styled-by-prettify">extern</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-pre=
ttify">"C"</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
IMAGE_DOS_HEADER __ImageBase</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">bool</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">IsInRea=
dOnlySectionOfMyExe</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
const</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">char</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">ptr</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">char</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">base</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">reinterpret_cast</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">char</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*>=
(&</span><span style=3D"color: #000;" class=3D"styled-by-prettify">__Im=
ageBase</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">if<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">ptr </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">base</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">false</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br> </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> IMAGE_NT_HEADERS </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">nt </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">reinterpret_cas=
t</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> IMAGE_NT_HEADERS </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">*>(</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">base</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">+</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> __ImageBase</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">e_lfanew</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br> </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">if</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
ptr </span><span style=3D"color: #660;" class=3D"styled-by-prettify">>=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">base</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">+</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> nt</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">-></span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">OptionalHeader</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">.</span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">SizeOfImage</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">false</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br> DWORD rva </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> ptr </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">-</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">base</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">rva </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> nt</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">-></span><span style=3D"color: #606;" class=3D"styled=
-by-prettify">OptionalHeader</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">.</span><span style=3D"color: #606;" class=3D"styled-by-p=
rettify">SizeOfHeaders</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">true</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
> </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">if</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">nt</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-></span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">FileHeader</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">NumberOfSections</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">false</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> IMAGE_SECTION_HEADERS </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">sections </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> IMAGE_FIRST_SECTION</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">nt</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> IMAGE_SECTION_HEADERS </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">endSections </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> sections </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">+</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> nt</span><span style=3D"color: #660;" class=3D"styled-by-prettify">->=
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">FileHeader=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">NumberOfSections</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">for</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> sections </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> endSections</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">++</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">sections</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">if</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">section=
s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-></sp=
an><span style=3D"color: #606;" class=3D"styled-by-prettify">Characteristic=
s</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">&</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> IMAGE_SCN_MEM_WRITE</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nbs=
p; </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">continue</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">if</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">((</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
rva </span><span style=3D"color: #660;" class=3D"styled-by-prettify">>=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> sectio=
ns</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-></s=
pan><span style=3D"color: #606;" class=3D"styled-by-prettify">VirtualAddres=
s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&&</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">rva </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> sections</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">-></span><span style=3D"color: #606;" class=3D"styled-b=
y-prettify">VirtualAddress</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">+</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> s=
ections</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-&g=
t;</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Misc</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span =
style=3D"color: #606;" class=3D"styled-by-prettify">VirtualSize</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">))</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br> &nb=
sp; </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">true<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">false</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span></div></code></div><br><br>Standardizing thi=
s seems like the wrong approach, since it's difficult to formally define an=
d the implementer of STL could already do this as an optimization in <span =
style=3D"font-family: courier new,monospace;">std::string</span> if they wa=
nted.<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_721_443310869.1418249078082--
------=_Part_720_2061518681.1418249078082--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 10 Dec 2014 14:14:33 -0800
Raw View
On Wednesday 10 December 2014 12:51:22 Matthew Fioravante wrote:
> On Wednesday, December 10, 2014 3:48:00 PM UTC-5, Thiago Macieira wrote:
> > On Wednesday 10 December 2014 12:44:20 Matthew Fioravante wrote:
> > > I'm really interested to know if there are any other use cases for such
> >
> > a
> >
> > > feature.
> >
> > If you're going to do this, I'd like to see something about virtual memory
>
> > there. With VMMs, you want to know whether the memory is:
> I'm not sure that makes sense to do in a cross platform way? Systems can
> have a lot of variation in how they implement virtual memory (or whether or
> not they implement it at all). How could we possibly come up with a set of
> factors which make sense on all possible platforms?
Please ask yourself the same questions.
How can you cross-platform and cross-architecturally determine if a given
pointer points to ROM, RAM or something else?
In any case, ROM and RAM are so 1980s. The overwhelming majority of
applications run in virtual memory systems, so I'd expect functionality that
matches their use-case. If you're developing an embedded system and running in
privileged, unpaged mode, you're probably developing the OS and you have the
function calls to do what you want.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Wed, 10 Dec 2014 22:32:05 +0000
Raw View
Please don't call it "is_rom", which would suggest that it is
physically unable to change.
On 12/10/14, Thiago Macieira <thiago@macieira.org> wrote:
> On Wednesday 10 December 2014 12:51:22 Matthew Fioravante wrote:
>> On Wednesday, December 10, 2014 3:48:00 PM UTC-5, Thiago Macieira wrote:
>> > On Wednesday 10 December 2014 12:44:20 Matthew Fioravante wrote:
>> > > I'm really interested to know if there are any other use cases for
>> > > such
>> >
>> > a
>> >
>> > > feature.
>> >
>> > If you're going to do this, I'd like to see something about virtual
>> > memory
>>
>> > there. With VMMs, you want to know whether the memory is:
>> I'm not sure that makes sense to do in a cross platform way? Systems can
>> have a lot of variation in how they implement virtual memory (or whether
>> or
>> not they implement it at all). How could we possibly come up with a set
>> of
>> factors which make sense on all possible platforms?
>
> Please ask yourself the same questions.
>
> How can you cross-platform and cross-architecturally determine if a given
> pointer points to ROM, RAM or something else?
>
> In any case, ROM and RAM are so 1980s. The overwhelming majority of
> applications run in virtual memory systems, so I'd expect functionality that
>
> matches their use-case. If you're developing an embedded system and running
> in
> privileged, unpaged mode, you're probably developing the OS and you have the
>
> function calls to do what you want.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel Open Source Technology Center
> PGP/GPG: 0x6EF45358; fingerprint:
> E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
>
> --
>
> ---
> 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.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Nevin Liber <nevin@eviloverlord.com>
Date: Wed, 10 Dec 2014 16:34:41 -0600
Raw View
--001a11c3d7ac5f374e0509e446ae
Content-Type: text/plain; charset=UTF-8
On 10 December 2014 at 14:35, Matthew Fioravante <fmatthew5876@gmail.com>
wrote:
>
> On Wednesday, December 10, 2014 3:15:16 PM UTC-5, Nevin ":-)" Liber wrote:
>>
>> On 10 December 2014 at 13:46, Matthew Fioravante <*fmatth...@gmail.com*>
>> wrote:
>>
>>>
>>>
>>> Would such a thing even be possible to implement portably?
>>>
>>
>> Doubtful. Think of memory mapping.
>>
>
> I think something memory mapped would need its own class such as
> "temporary". A class which says this memory exists now but may go away at
> anytime.
>
But it may never go away (or more importantly, not go away before any data
structures which reference it). And if you know that, you can take
advantage of that without having to make copies.
Read-only is insufficient. The other (arguably more important) piece of
> information you need to know is lifetime.
> Indeed. In my use case I want to determine whether the input string comes
> from read only static lifetime memory. Basically I need an absolute
> guarantee that the data will exist for the entire lifetime of the
> application and never be modified.
>
The only lifetime guarantee you need is that the data lives at least as
long as any reference to it.
Any statically determined system will likely be pessimistic with respect to
this, and if you really need this level of optimization, how can you afford
that pessimism?
For instance, a string literal inside a shared library outlives any
references in that shared library, but may not be alive for the entire
process. How do you plan on modeling that? Does the compiler have to know
whether the target object file is going into a shared library, static
library, or directly into an executable?
>
>> My major use cases involve applications which store a large amount of
>>> read-only string data at startup.
>>>
>>
>> If you have a large amount of program-lifetime read-only string data at
>> startup, you don't need this feature, as you already *know* that you
>> have program-lifetime read-only string data.
>>
>> The problem comes when you want to mix data with different lifetimes.
>> Code which does this microoptimization on a regular basis tends to be
>> fragile, buggy and difficult to reason about. You are better of separating
>> the concerns of managing the data lifetime from usage; classes shouldn't
>> conditionally manage lifetime.
>>
>
> I have a situation where most of the time the strings come from string
> literals. One example of this is setting up a factory. Each class type
> would have a string name which is used to instantiate that particular class
> from the factory. Most of the time these would come from string literals
> but in some cases the name might be constructed from other names.
>
Again, you *know* when it comes from string literals and when it is
constructed from other names. Instead of throwing that information away
and hoping that your factory can re-synthesize it based on the address,
just inform your factory of it. You can do something like:
class Factory
{
public:
void registerIt(std::string const& s, int i, bool manage = true)
{ theMap_[to_managed_string_ref(s, manage)] = i; }
void registerIt(std::string&& s, int i)
{ theMap_[to_managed_string_ref(std::move(s))] = i; }
void registerIt(std::string&& s, int i, bool manage) = delete;
template<size_t N>
void registerIt(const char(&a)[N], int i, bool manage = false)
{ theMap_[to_managed_string_ref(a, manage)] = i; }
private:
static boost::string_ref to_managed_string_ref(std::string&& s)
{
static std::mutex mux;
static std::deque<std::string> managedStrings;
std::lock_guard<std::mutex> lock(mux);
managedStrings.emplace_back(std::move(s));
return managedStrings.back();
}
static boost::string_ref to_managed_string_ref(boost::string_ref const&
sr, bool manage)
{ return manage ? to_managed_string_ref(std::string(sr)) : sr; }
std::map<boost::string_ref, int> theMap_;
};
The only unsafe case is when you have a local const char array you are
passing in, and that is easily caught during a code inspection.
--
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a11c3d7ac5f374e0509e446ae
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On 10 December 2014 at 14:35, Matthew Fioravante <span dir=
=3D"ltr"><<a href=3D"mailto:fmatthew5876@gmail.com" target=3D"_blank">fm=
atthew5876@gmail.com</a>></span> wrote:<br><div class=3D"gmail_extra"><d=
iv class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);=
border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div><br>On Wedn=
esday, December 10, 2014 3:15:16 PM UTC-5, Nevin ":-)" Liber wrot=
e:<blockquote style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-lef=
t-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" cla=
ss=3D"gmail_quote"><div dir=3D"ltr"><span class=3D"">On 10 December 2014 at=
13:46, Matthew Fioravante <span dir=3D"ltr"><<a><u><font color=3D"#0000=
80">fmatth...@gmail.com</font></u></a>></span> wrote:<br></span><div><di=
v class=3D"gmail_quote"><span class=3D""><blockquote style=3D"margin:0px 0p=
x 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left=
-width:1px;border-left-style:solid" class=3D"gmail_quote"><div dir=3D"ltr">=
<code><div><span style=3D"color:rgb(102,0,102)"><br></span><span style=3D"c=
olor:rgb(102,102,0)"></span></div></code><code><br>Would such a thing even =
be possible to implement portably? </code></div></blockquote><div><br></div=
></span><span class=3D""><div>Doubtful. Think of memory mapping.<br></div>=
</span></div></div></div></blockquote><div>=C2=A0</div><div>I think somethi=
ng memory mapped would need its own class such as "temporary". A =
class which says this memory exists now but may go away at anytime.=C2=A0</=
div></div></div></blockquote><div><br></div><div>But it may never go away (=
or more importantly, not go away before any data structures which reference=
it).=C2=A0 And if you know that, you can take advantage of that without ha=
ving to make copies.</div><div><br></div><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:r=
gb(204,204,204);border-left-style:solid;padding-left:1ex">=C2=A0Read-only i=
s insufficient. The other (arguably more important) piece of information y=
ou need to know is lifetime.</blockquote><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:r=
gb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr">=
<div><div>=C2=A0</div><div>Indeed. In my use case I want to determine wheth=
er the input string comes from read only static lifetime memory. Basically =
I need an absolute guarantee that the data will exist for the entire lifeti=
me of the application and never be modified.</div></div></div></blockquote>=
<div><br></div><div>The only lifetime guarantee you need is that the data l=
ives at least as long as any reference to it.</div><div><br></div><div>Any =
statically determined system will likely be pessimistic with respect to thi=
s, and if you really need this level of optimization, how can you afford th=
at pessimism?</div><div><br></div><div>For instance, a string literal insid=
e a shared library outlives any references in that shared library, but may =
not be alive for the entire process.=C2=A0 How do you plan on modeling that=
?=C2=A0 Does the compiler have to know whether the target object file is go=
ing into a shared library, static library, or directly into an executable?<=
/div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);borde=
r-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div><div>=C2=A0</div=
><blockquote style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left=
-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" clas=
s=3D"gmail_quote"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><span cl=
ass=3D""><div></div><div> </div><blockquote style=3D"margin:0px 0px 0px 0.8=
ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1p=
x;border-left-style:solid" class=3D"gmail_quote"><div dir=3D"ltr"><code>My =
major use cases involve applications which store a large amount of read-onl=
y string data at startup.</code></div></blockquote><div><br></div></span><s=
pan class=3D""><div>If you have a large amount of program-lifetime read-onl=
y string data at startup, you don't need this feature, as you already <=
i>know</i> that you have program-lifetime read-only string data.<br><br>The=
problem comes when you want to mix data with different lifetimes. Code wh=
ich does this microoptimization on a regular basis tends to be fragile, bug=
gy and difficult to reason about. You are better of separating the concern=
s of managing the data lifetime from usage; classes shouldn't condition=
ally manage lifetime.<br></div></span></div></div></div></blockquote><div>=
=C2=A0</div><div>I have a=C2=A0situation where most of the time the strings=
come from string literals. One example of this is setting up a factory. Ea=
ch class type would have a string name which is used=C2=A0to instantiate th=
at particular class from the factory. Most of the time these would come fro=
m string literals but in some cases the name might be constructed from othe=
r names.</div></div></div></blockquote><div><br></div><div>Again, you <i>kn=
ow</i> when it comes from string literals and when it is constructed from o=
ther names.=C2=A0 Instead of throwing that information away and hoping that=
your factory can re-synthesize it based on the address, just inform your f=
actory of it.=C2=A0 You can do something like:</div><div><br></div><div><p =
style=3D"margin:0px;font-size:11px;font-family:Menlo"><span style=3D"color:=
rgb(187,44,162)">class</span> Factory</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">{</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,16=
2)">public<span style=3D"color:rgb(0,0,0)">:</span></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">void</span> registerIt(std::string <span =
style=3D"color:rgb(187,44,162)">const</span>& s, <span style=3D"color:r=
gb(187,44,162)">int</span> i, <span style=3D"color:rgb(187,44,162)">bool</s=
pan> manage =3D <span style=3D"color:rgb(187,44,162)">true</span>)</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 { th=
eMap_[to_managed_string_ref(s, manage)] =3D i; }</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">void</span> registerIt(std::string&&a=
mp; s, <span style=3D"color:rgb(187,44,162)">int</span> i)</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 { th=
eMap_[to_managed_string_ref(std::move(s))] =3D i; }</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">void</span> registerIt(std::string&&a=
mp; s, <span style=3D"color:rgb(187,44,162)">int</span> i, <span style=3D"c=
olor:rgb(187,44,162)">bool</span> manage) =3D <span style=3D"color:rgb(187,=
44,162)">delete</span>;</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">template</span><size_t N></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">void</span> registerIt(<span style=3D"col=
or:rgb(187,44,162)">const</span> <span style=3D"color:rgb(187,44,162)">char=
</span>(&a)[N], <span style=3D"color:rgb(187,44,162)">int</span> i, <sp=
an style=3D"color:rgb(187,44,162)">bool</span> manage =3D <span style=3D"co=
lor:rgb(187,44,162)">false</span>)</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 { th=
eMap_[to_managed_string_ref(a, manage)] =3D i; }</p><p style=3D"margin:0px;=
font-size:11px;font-family:Menlo"><br></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,16=
2)">private<span style=3D"color:rgb(0,0,0)">:</span></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">static</span> boost::string_ref to_manage=
d_string_ref(std::string&& s)</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 {</p=
>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 <span style=3D"color:rgb(187,44,162)">static</span> std::mutex m=
ux;</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 <span style=3D"color:rgb(187,44,162)">static</span> std::deque&l=
t;std::string> managedStrings;</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 std::lock_guard<std::mutex> lock(mux);</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 managedStrings.emplace_back(std::move(s));</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 <span style=3D"color:rgb(187,44,162)">return</span> managedStrin=
gs.back();</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 }</p=
>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">static</span> boost::string_ref to_manage=
d_string_ref(boost::string_ref <span style=3D"color:rgb(187,44,162)">const<=
/span>& sr, <span style=3D"color:rgb(187,44,162)">bool</span> manage)</=
p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 {=C2=
=A0<span style=3D"color:rgb(187,44,162)">return</span> manage ? to_managed_=
string_ref(std::string(sr)) : sr; }</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 std:=
:map<boost::string_ref, <span style=3D"color:rgb(187,44,162)">int</span>=
> theMap_;</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">};</p></div></div>=
<div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra"><div>The on=
ly unsafe case is when you have a local const char array you are passing in=
, and that is easily caught during a code inspection.</div></div>-- <br><di=
v class=3D"gmail_signature">=C2=A0Nevin ":-)" Liber=C2=A0 <mai=
lto:<a href=3D"mailto:nevin@eviloverlord.com" target=3D"_blank">nevin@evilo=
verlord.com</a>>=C2=A0 (847) 691-1404</div>
</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c3d7ac5f374e0509e446ae--
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Wed, 10 Dec 2014 15:02:15 -0800 (PST)
Raw View
------=_Part_7285_1698426671.1418252535811
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
> when you do lookups with a StringView you don't murder performance by fir=
st constructing a temporary std::string for hashing
For this use case, you might consider using an ordered map with transparent=
comparator. If using an unordered map is essential, it would probably be s=
impler to extend heterogeneous lookup to unordered containers as per http:/=
/www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3573.html
--=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/.
------=_Part_7285_1698426671.1418252535811--
.
Author: Nevin Liber <nevin@eviloverlord.com>
Date: Wed, 10 Dec 2014 18:06:09 -0600
Raw View
--089e0158b79e817fa80509e58daf
Content-Type: text/plain; charset=UTF-8
On 10 December 2014 at 16:34, Nevin Liber <nevin@eviloverlord.com> wrote:
> class Factory
>
> {
>
> public:
>
> void registerIt(std::string const& s, int i, bool manage = true)
>
> { theMap_[to_managed_string_ref(s, manage)] = i; }
>
>
> void registerIt(std::string&& s, int i)
>
> { theMap_[to_managed_string_ref(std::move(s))] = i; }
>
>
> void registerIt(std::string&& s, int i, bool manage) = delete;
>
>
> template<size_t N>
>
> void registerIt(const char(&a)[N], int i, bool manage = false)
>
> { theMap_[to_managed_string_ref(a, manage)] = i; }
>
>
> private:
>
> static boost::string_ref to_managed_string_ref(std::string&& s)
>
> {
>
> static std::mutex mux;
>
> static std::deque<std::string> managedStrings;
>
>
> std::lock_guard<std::mutex> lock(mux);
>
> managedStrings.emplace_back(std::move(s));
>
> return managedStrings.back();
>
> }
>
>
> static boost::string_ref to_managed_string_ref(boost::string_ref const&
> sr, bool manage)
>
> { return manage ? to_managed_string_ref(std::string(sr)) : sr; }
>
>
> std::map<boost::string_ref, int> theMap_;
>
> };
>
You probably want to add:
template<size_t N>
void registerIt(char(&a)[N], int i)
{ theMap_[to_managed_string_ref(std::string(a))] = i; }
I make no claims as to the production readiness of this code. :-)
--
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--089e0158b79e817fa80509e58daf
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On 10 December 2014 at 16:34, Nevin Liber <span dir=3D"ltr=
"><<a href=3D"mailto:nevin@eviloverlord.com" target=3D"_blank">nevin@evi=
loverlord.com</a>></span> wrote:<br><div class=3D"gmail_extra"><div clas=
s=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-=
left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_ext=
ra"><div class=3D"gmail_quote"><div><p style=3D"margin:0px;font-size:11px;f=
ont-family:Menlo"><span style=3D"color:rgb(187,44,162)">class</span> Factor=
y</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">{</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,16=
2)">public<span style=3D"color:rgb(0,0,0)">:</span></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">void</span> registerIt(std::string <span =
style=3D"color:rgb(187,44,162)">const</span>& s, <span style=3D"color:r=
gb(187,44,162)">int</span> i, <span style=3D"color:rgb(187,44,162)">bool</s=
pan> manage =3D <span style=3D"color:rgb(187,44,162)">true</span>)</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 { th=
eMap_[to_managed_string_ref(s, manage)] =3D i; }</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">void</span> registerIt(std::string&&a=
mp; s, <span style=3D"color:rgb(187,44,162)">int</span> i)</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 { th=
eMap_[to_managed_string_ref(std::move(s))] =3D i; }</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">void</span> registerIt(std::string&&a=
mp; s, <span style=3D"color:rgb(187,44,162)">int</span> i, <span style=3D"c=
olor:rgb(187,44,162)">bool</span> manage) =3D <span style=3D"color:rgb(187,=
44,162)">delete</span>;</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">template</span><size_t N></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">void</span> registerIt(<span style=3D"col=
or:rgb(187,44,162)">const</span> <span style=3D"color:rgb(187,44,162)">char=
</span>(&a)[N], <span style=3D"color:rgb(187,44,162)">int</span> i, <sp=
an style=3D"color:rgb(187,44,162)">bool</span> manage =3D <span style=3D"co=
lor:rgb(187,44,162)">false</span>)</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 { th=
eMap_[to_managed_string_ref(a, manage)] =3D i; }</p><p style=3D"margin:0px;=
font-size:11px;font-family:Menlo"><br></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,16=
2)">private<span style=3D"color:rgb(0,0,0)">:</span></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">static</span> boost::string_ref to_manage=
d_string_ref(std::string&& s)</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 {</p=
>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 <span style=3D"color:rgb(187,44,162)">static</span> std::mutex m=
ux;</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 <span style=3D"color:rgb(187,44,162)">static</span> std::deque&l=
t;std::string> managedStrings;</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 std::lock_guard<std::mutex> lock(mux);</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 managedStrings.emplace_back(std::move(s));</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 <span style=3D"color:rgb(187,44,162)">return</span> managedStrin=
gs.back();</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 }</p=
>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">static</span> boost::string_ref to_manage=
d_string_ref(boost::string_ref <span style=3D"color:rgb(187,44,162)">const<=
/span>& sr, <span style=3D"color:rgb(187,44,162)">bool</span> manage)</=
p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 {=C2=
=A0<span style=3D"color:rgb(187,44,162)">return</span> manage ? to_managed_=
string_ref(std::string(sr)) : sr; }</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><b=
r></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 std:=
:map<boost::string_ref, <span style=3D"color:rgb(187,44,162)">int</span>=
> theMap_;</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">};</p></div></div>=
</div></div></blockquote><div><br></div><div>You probably want to add:</div=
><div><br></div><p style=3D"margin:0px;font-size:11px;font-family:Menlo">=
=C2=A0 =C2=A0=C2=A0<span style=3D"color:rgb(187,44,162)">template</span><=
;size_t N></p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 <spa=
n style=3D"color:rgb(187,44,162)">void</span> registerIt(<span style=3D"col=
or:rgb(187,44,162)">char</span>(&a)[N], <span style=3D"color:rgb(187,44=
,162)">int</span> i)</p>
<p style=3D"margin:0px;font-size:11px;font-family:Menlo">=C2=A0 =C2=A0 { th=
eMap_[to_managed_string_ref(std::string(a))] =3D i; }</p><div><br></div><di=
v>I make no claims as to the production readiness of this code. :-)</div></=
div>-- <br><div class=3D"gmail_signature">=C2=A0Nevin ":-)" Liber=
=C2=A0 <mailto:<a href=3D"mailto:nevin@eviloverlord.com" target=3D"_blan=
k">nevin@eviloverlord.com</a>>=C2=A0 (847) 691-1404</div>
</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--089e0158b79e817fa80509e58daf--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 10 Dec 2014 17:36:56 -0800 (PST)
Raw View
------=_Part_2351_64579093.1418261816274
Content-Type: multipart/alternative;
boundary="----=_Part_2352_901574316.1418261816274"
------=_Part_2352_901574316.1418261816274
Content-Type: text/plain; charset=UTF-8
On Wednesday, December 10, 2014 5:35:24 PM UTC-5, Nevin ":-)" Liber wrote:
>
>
> The only unsafe case is when you have a local const char array you are
> passing in, and that is easily caught during a code inspection.
>
>
That case is just risky enough to turn me off to the solution of assuming
any reference to char array is a string literal. I suppose if you could
somehow get the starting address of the stack and compare it to the address
of a local variable you could check if its a local array vs a string
literal.
I would also add an overload for non-const arrays, as those have to be
managed because later someone can go and change the contents out from under
you. This still doesn't help in the case where you have an array inside an
object which was heap allocated or created some other way. The edge cases
are endless.
Finally, it also doesn't help if you've got a string_view which was
initialized to point to a string literal, passed down the call stack
several times, and then finally makes it to your factory.
It's a shame we have these string_literals which already get efficiently
allocated storage by the compiler which is so difficult to leverage. Even
having the following would be enough for me.
bool is_string_literal(const char* s);
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2352_901574316.1418261816274
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, December 10, 2014 5:35:24 PM UTC-5, =
Nevin ":-)" Liber wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div d=
ir=3D"ltr"><div><br></div><div><div>The only unsafe case is when you have a=
local const char array you are passing in, and that is easily caught durin=
g a code inspection.</div></div><br></div></blockquote><div><br></div><div>=
That case is just risky enough to turn me off to the solution of assuming a=
ny reference to char array is a string literal. I suppose if you coul=
d somehow get the starting address of the stack and compare it to the addre=
ss of a local variable you could check if its a local array vs a string lit=
eral.</div><div><br></div><div>I would also add an overload for non-const a=
rrays, as those have to be managed because later someone can go and change =
the contents out from under you. <span style=3D"font-size: 13px;">This=
still doesn't help in the case where you have an array inside an object wh=
ich was heap allocated or created some other way. The edge cases are endles=
s.</span></div><div><br></div><div>Finally, it also doesn't help if you've =
got a string_view which was initialized to point to a string literal, passe=
d down the call stack several times, and then finally makes it to your fact=
ory.</div><div><br></div><div>It's a shame we have these string_literals wh=
ich already get efficiently allocated storage by the compiler which is so d=
ifficult to leverage. Even having the following would be enough for me.</di=
v><div><br></div><div><div class=3D"prettyprint" style=3D"border: 1px solid=
rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250,=
250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><font col=
or=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-prettify">bo=
ol</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> is_stri=
ng_literal</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> s</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">);</span></font></div></code></div><br><br></=
div><div><br></div><div><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_2352_901574316.1418261816274--
------=_Part_2351_64579093.1418261816274--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 10 Dec 2014 18:08:16 -0800 (PST)
Raw View
------=_Part_7700_807472269.1418263696334
Content-Type: multipart/alternative;
boundary="----=_Part_7701_1237259690.1418263696335"
------=_Part_7701_1237259690.1418263696335
Content-Type: text/plain; charset=UTF-8
On Wednesday, December 10, 2014 6:02:15 PM UTC-5, Edward Catmur wrote:
>
> > when you do lookups with a StringView you don't murder performance by
> first constructing a temporary std::string for hashing
>
> For this use case, you might consider using an ordered map with
> transparent comparator.
Unfortunately std::map is pretty useless. I have yet to find a single place
where I wanted a std::map. Usually its either a hash table like
unordered_map for a lookup based data structure or a sorted vector for an
ordered data structure.
> If using an unordered map is essential, it would probably be simpler to
> extend heterogeneous lookup to unordered containers as per
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3573.html
I don't believe it is so easy to extend to unordered_map in a generic
fashion because to do so would require that 2 objects which are equivalent
also hash to the exact same value. For standard library types like string
and string_view this is easy enough to fix but for user defined types its
impossible because we don't have access to how other types we haven't
written are hashed.
The real use case for heterogeneous lookup is efficient string lookup. I'm
not sure how many other domains benefit from it. I'd be happy with a one
off solution of having an STL string_map and string_set to fix this issue
just for std::string and std::string_view. That's essentially what I do in
my code.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_7701_1237259690.1418263696335
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, December 10, 2014 6:02:15 PM UTC-5, =
Edward Catmur wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">> when =
you do lookups with a StringView you don't murder performance by first cons=
tructing a temporary std::string for hashing
<br>
<br>For this use case, you might consider using an ordered map with transpa=
rent comparator.</blockquote><div><br></div><div>Unfortunately std::map is =
pretty useless. I have yet to find a single place where I wanted a std::map=
.. Usually its either a hash table like unordered_map for a lookup based dat=
a structure or a sorted vector for an ordered data structure.</div><div>&nb=
sp;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"> If using an unordere=
d map is essential, it would probably be simpler to extend heterogeneous lo=
okup to unordered containers as per <a href=3D"http://www.open-std.org/jtc1=
/sc22/wg21/docs/papers/2013/n3573.html" target=3D"_blank" onmousedown=3D"th=
is.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjt=
c1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2013%2Fn3573.html\46sa\75D\46sntz\0751\4=
6usg\75AFQjCNEo25j-Q143EfVSI8PppC1h_pYp6A';return true;" onclick=3D"this.hr=
ef=3D'http://www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2F=
sc22%2Fwg21%2Fdocs%2Fpapers%2F2013%2Fn3573.html\46sa\75D\46sntz\0751\46usg\=
75AFQjCNEo25j-Q143EfVSI8PppC1h_pYp6A';return true;">http://www.open-std.org=
/jtc1/<wbr>sc22/wg21/docs/papers/2013/<wbr>n3573.html</a></blockquote><div>=
<br></div><div>I don't believe it is so easy to extend to unordered_map in =
a generic fashion because to do so would require that 2 objects which are e=
quivalent also hash to the exact same value. For standard library types lik=
e string and string_view this is easy enough to fix but for user defined ty=
pes its impossible because we don't have access to how other types we haven=
't written are hashed.</div><div><br></div><div>The real use case for heter=
ogeneous lookup is efficient string lookup. I'm not sure how many other dom=
ains benefit from it. I'd be happy with a one off solution of having an STL=
string_map and string_set to fix this issue just for std::string and std::=
string_view. That's essentially what I do in my code.</div><div><br></div><=
div><br></div><div><br></div><div><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_7701_1237259690.1418263696335--
------=_Part_7700_807472269.1418263696334--
.
Author: Nevin Liber <nevin@eviloverlord.com>
Date: Wed, 10 Dec 2014 20:48:05 -0600
Raw View
--089e0158b50ca355a30509e7d00a
Content-Type: text/plain; charset=UTF-8
On 10 December 2014 at 20:08, Matthew Fioravante <fmatthew5876@gmail.com>
wrote:
> The real use case for heterogeneous lookup is efficient string lookup. I'm
> not sure how many other domains benefit from it.
Lots would; any place you don't want to create an expensive object just to
do a comparison.
Personally, I think we got the unordered containers wrong. Because hashing
is so closely tied to equality (a==b implies hash(a)==hash(b)), they really
should be specified in the same function object. Maybe for STL2 (no, that
isn't a real proposal yet)...
--
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--089e0158b50ca355a30509e7d00a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra">On 10 December 2014 at 20:08, M=
atthew Fioravante <span dir=3D"ltr"><<a href=3D"mailto:fmatthew5876@gmai=
l.com" target=3D"_blank">fmatthew5876@gmail.com</a>></span> wrote:<br><d=
iv class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:=
0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The real use case f=
or heterogeneous lookup is efficient string lookup. I'm not sure how ma=
ny other domains benefit from it.</blockquote></div><br>Lots would; any pla=
ce you don't want to create an expensive object just to do a comparison=
..</div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">Pers=
onally, I think we got the unordered containers wrong.=C2=A0 Because hashin=
g is so closely tied to equality (a=3D=3Db implies hash(a)=3D=3Dhash(b)), t=
hey really should be specified in the same function object.=C2=A0 Maybe for=
STL2 (no, that isn't a real proposal yet)...</div><div class=3D"gmail_=
extra"><br clear=3D"all"><div><br></div>-- <br><div class=3D"gmail_signatur=
e">=C2=A0Nevin ":-)" Liber=C2=A0 <mailto:<a href=3D"mailto:nev=
in@eviloverlord.com" target=3D"_blank">nevin@eviloverlord.com</a>>=C2=A0=
(847) 691-1404</div>
</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--089e0158b50ca355a30509e7d00a--
.
Author: Nevin Liber <nevin@eviloverlord.com>
Date: Wed, 10 Dec 2014 20:52:17 -0600
Raw View
--001a11390a8e9bfc770509e7df62
Content-Type: text/plain; charset=UTF-8
On 10 December 2014 at 19:36, Matthew Fioravante <fmatthew5876@gmail.com>
wrote:
> It's a shame we have these string_literals which already get efficiently
> allocated storage by the compiler which is so difficult to leverage. Even
> having the following would be enough for me.
>
> bool is_string_literal(const char* s);
>
I'll ask again: please explain how this helps you in the case where the
string literal is in a shared library which may be unloaded.
--
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a11390a8e9bfc770509e7df62
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On 10 December 2014 at 19:36, Matthew Fioravante <span dir=3D"ltr"><<a h=
ref=3D"mailto:fmatthew5876@gmail.com" target=3D"_blank">fmatthew5876@gmail.=
com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>It's a=
shame we have these string_literals which already get efficiently allocate=
d storage by the compiler which is so difficult to leverage. Even having th=
e following would be enough for me.</div><div><br></div><div><div style=3D"=
border:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb=
(250,250,250)"><code><div><font color=3D"#660066"><span style=3D"color:#008=
">bool</span><span style=3D"color:#000"> is_string_literal</span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#008">const</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">char</span><span style=
=3D"color:#660">*</span><span style=3D"color:#000"> s</span><span style=3D"=
color:#660">);</span></font></div></code></div><div class=3D"yj6qo ajU"><di=
v id=3D":36z" class=3D"ajR" tabindex=3D"0"></div></div></div></blockquote><=
/div><br>I'll ask again: =C2=A0please explain how this helps you in the=
case where the string literal is in a shared library which may be unloaded=
..<br>-- <br><div class=3D"gmail_signature">=C2=A0Nevin ":-)" Libe=
r=C2=A0 <mailto:<a href=3D"mailto:nevin@eviloverlord.com" target=3D"_bla=
nk">nevin@eviloverlord.com</a>>=C2=A0 (847) 691-1404</div>
</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11390a8e9bfc770509e7df62--
.
Author: Myriachan <myriachan@gmail.com>
Date: Wed, 10 Dec 2014 18:56:22 -0800 (PST)
Raw View
------=_Part_5319_1698762850.1418266582794
Content-Type: multipart/alternative;
boundary="----=_Part_5320_312133085.1418266582794"
------=_Part_5320_312133085.1418266582794
Content-Type: text/plain; charset=UTF-8
On Wednesday, December 10, 2014 6:52:58 PM UTC-8, Nevin ":-)" Liber wrote:
>
>
> On 10 December 2014 at 19:36, Matthew Fioravante <fmatth...@gmail.com
> <javascript:>> wrote:
>
>> It's a shame we have these string_literals which already get efficiently
>> allocated storage by the compiler which is so difficult to leverage. Even
>> having the following would be enough for me.
>>
>> bool is_string_literal(const char* s);
>>
>
> I'll ask again: please explain how this helps you in the case where the
> string literal is in a shared library which may be unloaded.
>
Well, you'd just have it return false for unloadable code. (Unless you're
a shared library that has statically linked the library implementing
it--then you know that your own strings have the same lifetime as
yourself. This situation only really happens in Windows NT, though.)
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_5320_312133085.1418266582794
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, December 10, 2014 6:52:58 PM UTC-8, Nevin ":=
-)" Liber 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"lt=
r"><div><br><div class=3D"gmail_quote">On 10 December 2014 at 19:36, Matthe=
w Fioravante <span dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank=
" gdf-obfuscated-mailto=3D"hrQDE8qrXzcJ" onmousedown=3D"this.href=3D'javasc=
ript:';return true;" onclick=3D"this.href=3D'javascript:';return true;">fma=
tth...@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote"=
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv>It's a shame we have these string_literals which already get efficiently=
allocated storage by the compiler which is so difficult to leverage. Even =
having the following would be enough for me.</div><div><br></div><div><div =
style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-=
color:rgb(250,250,250)"><code><div><font color=3D"#660066"><span style=3D"c=
olor:#008">bool</span><span style=3D"color:#000"> is_string_literal</span><=
span style=3D"color:#660">(</span><span style=3D"color:#008">const</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">char</span><spa=
n style=3D"color:#660">*</span><span style=3D"color:#000"> s</span><span st=
yle=3D"color:#660">);</span></font></div></code></div></div></blockquote></=
div><br>I'll ask again: please explain how this helps you in the case=
where the string literal is in a shared library which may be unloaded.</di=
v></div></blockquote><div><br>Well, you'd just have it return false for unl=
oadable code. (Unless you're a shared library that has statically lin=
ked the library implementing it--then you know that your own strings have t=
he same lifetime as yourself. This situation only really happens in W=
indows NT, though.) <br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_5320_312133085.1418266582794--
------=_Part_5319_1698762850.1418266582794--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 10 Dec 2014 20:44:22 -0800
Raw View
On Wednesday 10 December 2014 18:56:22 Myriachan wrote:
> On Wednesday, December 10, 2014 6:52:58 PM UTC-8, Nevin ":-)" Liber wrote:
> > On 10 December 2014 at 19:36, Matthew Fioravante <fmatth...@gmail.com
> >
> > <javascript:>> wrote:
> >> It's a shame we have these string_literals which already get efficiently
> >> allocated storage by the compiler which is so difficult to leverage. Even
> >> having the following would be enough for me.
> >>
> >> bool is_string_literal(const char* s);
> >
> > I'll ask again: please explain how this helps you in the case where the
> > string literal is in a shared library which may be unloaded.
>
> Well, you'd just have it return false for unloadable code. (Unless you're
> a shared library that has statically linked the library implementing
> it--then you know that your own strings have the same lifetime as
> yourself. This situation only really happens in Windows NT, though.)
Making the function depend on the location of the caller is interesting, but
probably prone to subtle errors. Imagine what would happen if you tried to use
it in a library. In fact, imagine what happens if you use it in inline code
that gets merged at runtime from multiple libraries.
dlopen has that "issue".
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Sean Middleditch <sean.middleditch@gmail.com>
Date: Sat, 13 Dec 2014 15:56:46 -0800 (PST)
Raw View
------=_Part_1295_54958305.1418515006032
Content-Type: multipart/alternative;
boundary="----=_Part_1296_266263925.1418515006032"
------=_Part_1296_266263925.1418515006032
Content-Type: text/plain; charset=UTF-8
On Wednesday, December 10, 2014 2:35:24 PM UTC-8, Nevin ":-)" Liber wrote:
>
> The only unsafe case is when you have a local const char array you are
> passing in, and that is easily caught during a code inspection.
>
I've run into enough bugs over the years in both C and C++ to confidently
say that no, it isn't.
I think that if we had a way to verify that a parameter is constexpr then
that would solve this problem in most interesting cases. The idea has been
floated before; I don't think there's been a paper on it, though. There is
N4121 of course, though that library itself could use a constexpr
overloading facility for safety (or perhaps use a user-defined literal
operator as its sole method of construction).
--
> Nevin ":-)" Liber <mailto:ne...@eviloverlord.com <javascript:>> (847)
> 691-1404
>
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1296_266263925.1418515006032
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, December 10, 2014 2:35:24 PM UTC-8, Nevin ":=
-)" Liber 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"lt=
r"><div class=3D"gmail_quote"><div><p style=3D"margin:0px;font-size:11px;fo=
nt-family:Menlo"><span style=3D"font-family: Arial, Helvetica, sans-serif; =
font-size: 13px;">The only unsafe case is when you have a local const char =
array you are passing in, and that is easily caught during a code inspectio=
n.</span></p></div></div></div></blockquote><div><br></div><div>I've run in=
to enough bugs over the years in both C and C++ to confidently say that no,=
it isn't.</div><div><br></div><div>I think that if we had a way to verify =
that a parameter is constexpr then that would solve this problem in most in=
teresting cases. The idea has been floated before; I don't think there's be=
en a paper on it, though. There is N4121 of course, though that library its=
elf could use a constexpr overloading facility for safety (or perhaps use a=
user-defined literal operator as its sole method of construction).</div><d=
iv><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
-- <br><div> Nevin ":-)" Liber <mailto:<a href=3D"javascript:=
" target=3D"_blank" gdf-obfuscated-mailto=3D"QbxpkmK_sNAJ" onmousedown=3D"t=
his.href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:'=
;return true;">ne...@eviloverlord.com</a><wbr>> (847) 691-1404</di=
v>
</div>
</blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1296_266263925.1418515006032--
------=_Part_1295_54958305.1418515006032--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 14 Dec 2014 03:17:01 +0200
Raw View
On 14 December 2014 at 01:56, Sean Middleditch
<sean.middleditch@gmail.com> wrote:
> On Wednesday, December 10, 2014 2:35:24 PM UTC-8, Nevin ":-)" Liber wrote:
>>
>> The only unsafe case is when you have a local const char array you are
>> passing in, and that is easily caught during a code inspection.
>
>
> I've run into enough bugs over the years in both C and C++ to confidently
> say that no, it isn't.
>
> I think that if we had a way to verify that a parameter is constexpr then
> that would solve this problem in most interesting cases. The idea has been
> floated before; I don't think there's been a paper on it, though. There is
I think the idea gets shot down every time someone mentions it.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: "Daniel Gutson" <danielgutson@gmail.com>
Date: Sun, 14 Dec 2014 13:40:39 +0000
Raw View
--part4804-boundary-1248797178-1753344146
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
I think this shouldn't be a language feature, but an OS feature. In the sam=
e way either C or C++ don't have an mlock feature, this also looks more lik=
e a system call to me.
Moreover, lif you are looking for a portable optimization, I think you are =
taking the wrong approach since a facility like this may take nondeterminis=
tic time, and I can think of very slow implementations in some OSs (just th=
ink about the cost of a system call).
Also, what if the pointer is in other TLS for example?
I think that the problem I'm assuming you want to address should be solved =
at the design phase of the application, e.g. by explicitly differentiating =
whether a key is a literal or a temporal, maybe by a wrapping class to dist=
inguish the type.
Finally, I suggest that when proposing an optimization, also provide a prot=
otype with some benchmarks to see if it's worth the effort to discuss it.=
=20
-----Original Message-----
From: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 10 Dec 2014 11:46:42=20
To: <std-proposals@isocpp.org>
Reply-To: std-proposals@isocpp.org
Subject: [std-proposals] Classifying pointers
It would be really nice to be able to determine whether at arbitrary=20
pointer points to read only global memory or local memory (heap, stack,=20
etc..).
Here is the motivating example:
//Returns true if p points to an address in global read only memory
bool is_rom(const void* p);
//Some class which stores strings
struct Store {
void store(string_view s) {
if(!is_rom(s.data()) {
_extra_storage.push_back(std::string(s));
s =3D _extra_storage.back();
}
_strings.insert(s);
}
std::unordered_set<StringView> _strings;
std::list<std::string> _extra_storage; //There are more efficient ways to=
=20
do this
};
//Examples
const char f[] =3D "faz";
char g[] =3D "gaz";
void example() {
char a[] =3D "bar";
const char* b =3D "baz";
std::string c =3D "saz";
assert(is_rom("Foo") =3D=3D true); //string literals are global and read =
only
assert(is_rom(a) =3D=3D false); //a decays to pointer which points to add=
ress=20
on the stack
assert(is_rom(b) =3D=3D true); //b points to string literal which is glob=
al
assert(is_rom(c.c_str()) =3D false); //heap allocated
assert(is_rom(f) =3D=3D true); //f decays to pointer which points to addr=
ess=20
in read only global memory
assert(is_rom(g) =3D=3D true); //g decays to pointer which points to addr=
ess=20
in RW global memory
The motivating example here is with read only strings. The C++ runtime=20
allocates read-only storage for string literals so there is no reason to=20
make a second copy of them and store it at runtime. Store::store checks=20
whether the input string comes from read only global memory and if it does=
=20
just adds it to the set. If the string comes from either a user created=20
buffer (stack, heap, etc..), or comes from global memory which is not read=
=20
only (can be overwritten later), we make a copy and store that.
A better version of this might be to have set of different memory=20
classifications:
enum class memory_class {
unknown, //Unknown memory address (maybe memory mapped io, unmapped=20
pages, or other strange things)
stack, //Points to memory on the stack
heap, //Points to memory on the heap
static, //Points to global read/write memory
rom //Points to global read only memory (may exist within a ROM)
};
memory_class get_memory_class(const void* p);
Would such a thing even be possible to implement portably? Does anyone=20
think exposing this information would be a bad idea?
My major use cases involve applications which store a large amount of=20
read-only string data at startup. Examples include finance applications=20
with dictionaries of symbols and video games with resource names.
--=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/.
--=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/.
--part4804-boundary-1248797178-1753344146
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><=
meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type"></h=
ead><body>I think this shouldn't be a language feature, but an OS feature. =
In the same way either C or C++ don't have an mlock feature, this also look=
s more like a system call to me.<br/>Moreover, lif you are looking for a po=
rtable optimization, I think you are taking the wrong approach since a faci=
lity like this may take nondeterministic time, and I can think of very slow=
implementations in some OSs (just think about the cost of a system call).<=
br/>Also, what if the pointer is in other TLS for example?<br/><br/>I think=
that the problem I'm assuming you want to address should be solved at the =
design phase of the application, e.g. by explicitly differentiating whether=
a key is a literal or a temporal, maybe by a wrapping class to distinguish=
the type.<br/><br/>Finally, I suggest that when proposing an optimization,=
also provide a prototype with some benchmarks to see if it's worth the eff=
ort to discuss it. <hr/><div><b>From: </b> Matthew Fioravante <fmatthew5=
876@gmail.com>
</div><div><b>Date: </b>Wed, 10 Dec 2014 11:46:42 -0800 (PST)</div><div><b>=
To: </b><std-proposals@isocpp.org></div><div><b>ReplyTo: </b> std-pro=
posals@isocpp.org
</div><div><b>Subject: </b>[std-proposals] Classifying pointers</div><div><=
br/></div><div dir=3D"ltr">It would be really nice to be able to determine =
whether at arbitrary pointer points to read only global memory or local mem=
ory (heap, stack, etc..).<br><br>Here is the motivating example:<br><code><=
br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250)=
; border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px;=
word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprett=
yprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">//Returns=
true if p points to an address in global read only memory<br>bool</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> is_rom</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">const void</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> p</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br><br>//Some class which stores strings<br></span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Store</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> store</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
string_view s</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(!</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">is_rom</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">s</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">data</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">())</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br> &=
nbsp; _extra_storage</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>push_back</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">string</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">s</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">));</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> s </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> _extra_storage</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">back</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br> _strings</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">insert</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">s</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> std=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">unordered_set</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n style=3D"color: #606;" class=3D"styled-by-prettify">StringView</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> _strings</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br> std</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">list</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">string</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
_extra_storage</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #800;" class=3D"styled-by-prettify">//There are mo=
re efficient ways to do this</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">//Examples</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"></span><span style=3D"color: #008;" class=3D"styled-by-prettify"><br>cons=
t char f[] =3D "faz";<br>char g[] =3D "gaz";<br><br>void</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> example</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">char</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> a</span><span 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: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #080;" class=3D"styled-by-prettify">"bar"</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">char</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> b </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #080;" class=3D"styled-by-prettify">"baz"</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br> std</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">string</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> c </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"sty=
led-by-prettify">"saz"</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br><br></span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
></span><br><code><code class=3D"prettyprint"><span style=3D"color: #008;" =
class=3D"styled-by-prettify"> assert</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">is_rom</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #080;" class=3D"styled-by=
-prettify">"Foo"</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">true</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">); //string literals are global=
and read only<br> assert(is_rom(a) =3D=3D false); //a decays to poin=
ter which points to address on the stack<br> assert(is_rom(b) =3D=3D =
true); //b points to string literal which is global<br> assert(is_rom=
(c.c_str()) =3D false); //heap allocated<br> assert(is_rom(f) =3D=3D =
true); //f decays to pointer which points to address in read only global me=
mory</span></code></code><br><code><code class=3D"prettyprint"><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><code><code class=3D"prettyp=
rint"><code><code class=3D"prettyprint"><span style=3D"color: #660;" class=
=3D"styled-by-prettify"> assert(is_rom(g) =3D=3D true); //g decays to=
pointer which points to address in RW global memory</span></code></code></=
code></code></span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span></code></code></div></code></div><br>The motivating example he=
re is with read only strings. The C++ runtime allocates read-only storage f=
or string literals so there is no reason to make a second copy of them and =
store it at runtime. Store::store checks whether the input string comes fro=
m read only global memory and if it does just adds it to the set. If the st=
ring comes from either a user created buffer (stack, heap, etc..), or comes=
from global memory which is not read only (can be overwritten later), we m=
ake a copy and store that.<br><br>A better version of this might be to have=
set of different memory classifications:<br><br><div class=3D"prettyprint"=
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 class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color:=
#606;" class=3D"styled-by-prettify">enum class memory_class {<br> un=
known, //Unknown memory address (maybe memory mapped io, unmapped pages, or=
other strange things)<br> stack, //Points to memory on the stack<br>=
heap, //Points to memory on the heap<br> static, //Points to g=
lobal read/write memory<br> rom //Points to global read only memory (=
may exist within a ROM)<br>};<br><br>memory_class get_memory_class(const vo=
id* p);<br></span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
></span></div></code></div><br>Would such a thing even be possible to imple=
ment portably? Does anyone think exposing this information would be a bad i=
dea?<br><br>My major use cases involve applications which store a large amo=
unt of read-only string data at startup. Examples include finance applicati=
ons with dictionaries of symbols and video games with resource names.<br></=
code><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
</body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--part4804-boundary-1248797178-1753344146--
.