220 19523 <C2EDA5EB-F9FE-4D0F-93FF-ED88F371E158@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: try_realloc
Date: Sun, 2 Aug 2015 14:29:13 +0800
Lines: 103
Approved: news@gmane.org
Message-ID: <C2EDA5EB-F9FE-4D0F-93FF-ED88F371E158@gmail.com>
References: <30f59ec7-0712-48fb-9df0-d66e3fe80c3c@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_DD0B3623-5087-4177-B5D5-58D786462855"
X-Trace: ger.gmane.org 1438496968 3472 80.91.229.3 (2 Aug 2015 06:29:28 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 2 Aug 2015 06:29:28 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBQHR62WQKGQEIWRXCKQ@isocpp.org Sun Aug 02 08:29:23 2015
Return-path: <std-proposals+bncBCW25A7E3QCRBQHR62WQKGQEIWRXCKQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f70.google.com ([209.85.220.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBQHR62WQKGQEIWRXCKQ@isocpp.org>)
	id 1ZLmlv-0004a6-61
	for gclcip-std-proposals@m.gmane.org; Sun, 02 Aug 2015 08:29:23 +0200
Original-Received: by pacom8 with SMTP id om8sf203605857pac.3
        for <gclcip-std-proposals@m.gmane.org>; Sat, 01 Aug 2015 23:29:21 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:content-type:message-id:mime-version
         :subject:date:references:to:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=hR6W4ioN4xR4nADocQbnUGNotw86MbwGGcZkIDBEJiA=;
        b=By3/XwZHenzrrGWDhJ72gInO16DcZ/quJu8BOmJg+aMxPeML+BlNHD8Po1Pmnoi0U/
         KqQcFZH8lYze6zjorWEcmJClQaUrwqmLLLilNqY/qUeVvA3mfQI6dkJn24xBjLnzXmgR
         dh4g4qZBaQUQvKdAVvkkctnEa5yx+YTYXCH9Kuwkl8xYqKFL6ula4Olu/HEa3p/1F3EN
         DqFpHaNUnVAOqnWs4/NyO6O6By7JEh5qlO3QwcbNgfIoOYLgt6Dvpn8SAwniOb4Ygn1T
         umPAxO5ZnCOWEYUouhZcUFHylcmreELal8bAM+ARnyNyL9eKF7Tm1vFDrVyPjsDIUvRJ
         BVuA==
X-Gm-Message-State: ALoCoQkYxRP3B5XIQFfshOHR7CaaWxJsFA6qb/IZqPD7WulOo8ERB5FemucE3haYTYlY/JsnaYpL
X-Received: by 10.67.23.138 with SMTP id ia10mr10749224pad.18.1438496961324;
        Sat, 01 Aug 2015 23:29:21 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.162.17 with SMTP id l17ls1387654ioe.19.gmail; Sat, 01 Aug
 2015 23:29:20 -0700 (PDT)
X-Received: by 10.66.63.8 with SMTP id c8mr24794858pas.122.1438496960588;
        Sat, 01 Aug 2015 23:29:20 -0700 (PDT)
Original-Received: from mail-pa0-x229.google.com (mail-pa0-x229.google.com. [2607:f8b0:400e:c03::229])
        by mx.google.com with ESMTPS id kk7si20215134pab.132.2015.08.01.23.29.20
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 01 Aug 2015 23:29:20 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c03::229 as permitted sender) client-ip=2607:f8b0:400e:c03::229;
Original-Received: by pabkd10 with SMTP id kd10so65873740pab.2
        for <std-proposals@isocpp.org>; Sat, 01 Aug 2015 23:29:20 -0700 (PDT)
X-Received: by 10.66.65.229 with SMTP id a5mr24568337pat.11.1438496960513;
        Sat, 01 Aug 2015 23:29:20 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.186])
        by smtp.gmail.com with ESMTPSA id om5sm3834695pbb.37.2015.08.01.23.29.17
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sat, 01 Aug 2015 23:29:19 -0700 (PDT)
In-Reply-To: <30f59ec7-0712-48fb-9df0-d66e3fe80c3c@isocpp.org>
X-Mailer: Apple Mail (2.2098)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c03::229 as permitted
 sender) smtp.mail=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:19523
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19523>

--Apple-Mail=_DD0B3623-5087-4177-B5D5-58D786462855
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9308=E2=80=9302, at 1:23 PM, denis bider <isocppgroup@denis=
bider.com> wrote:
>=20
> It strikes me that the language relatively desperately needs a function l=
ike try_realloc. This function would work like realloc, except that it woul=
d guarantee to fail if memory can't be reallocated in place.
>=20
> It seems to me that, even if property like is_relocatable or is_location_=
agnostic is introduced, allowing use of realloc with containers of such typ=
es, a function like try_realloc would be remain highly useful for container=
s of other types. It would avoid having to deep-copy objects if memory can =
be reallocated in place.
>=20
> On Windows, this is already available like this:
>=20
> HeapReAlloc(GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, p, n);

It would be nice to have members in std::allocator_traits, called grow_allo=
cation and shrink_allocation. They could simply return false by default, to=
 indicate failure.

I wrote a very fast tokenizer, a while back, using a custom string class wh=
ich reserved maximum space on construction, and shrink to fit when the next=
 token was found. I had to depart from the standard allocator model and rol=
l my own string class. It really should be doable with the standard library=
..

Sooner or later, if nobody else proposes it, I will.

--=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/.

--Apple-Mail=_DD0B3623-5087-4177-B5D5-58D786462855
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9308=
=E2=80=9302, at 1:23 PM, denis bider &lt;<a href=3D"mailto:isocppgroup@deni=
sbider.com" class=3D"">isocppgroup@denisbider.com</a>&gt; wrote:</div><br c=
lass=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" class=
=3D""><div class=3D"">It strikes me that the language relatively desperatel=
y needs a function like <font face=3D"courier new,monospace" class=3D"">try=
_realloc</font>. This function would work like <font face=3D"courier new,mo=
nospace" class=3D"">realloc</font>, except that it would guarantee to fail =
if memory can't be reallocated in place.</div><div class=3D""><br class=3D"=
"></div><div class=3D"">It seems to me that, even if&nbsp;property like <fo=
nt face=3D"courier new,monospace" class=3D"">is_relocatable</font> or <font=
 face=3D"courier new,monospace" class=3D"">is_location_agnostic</font> is i=
ntroduced, allowing use of <font face=3D"courier new,monospace" class=3D"">=
realloc</font> with containers of such&nbsp;types,&nbsp;a function like&nbs=
p;<font face=3D"courier new,monospace" class=3D"">try_realloc</font> would =
be remain highly useful for containers of other types. It would avoid havin=
g to deep-copy objects if memory can be reallocated in place.</div><div cla=
ss=3D""><br class=3D""></div><div class=3D"">On Windows, this is already av=
ailable like this:</div><div class=3D""><br class=3D""></div><div class=3D"=
">HeapReAlloc(GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, p, n);</div></d=
iv></div></blockquote><br class=3D""></div><div>It would be nice to have me=
mbers in <font face=3D"Courier" class=3D"">std::allocator_traits</font>, ca=
lled <font face=3D"Courier" class=3D"">grow_allocation</font> and <font fac=
e=3D"Courier" class=3D"">shrink_allocation</font>. They could simply return=
 <font face=3D"Courier" class=3D"">false</font> by default, to indicate fai=
lure.</div><div><br class=3D""></div><div>I wrote a very fast tokenizer, a =
while back, using a custom string class which reserved maximum space on con=
struction, and shrink to fit when the next token was found. I had to depart=
 from the standard allocator model and roll my own string class. It really =
should be doable with the standard library.</div><div><br class=3D""></div>=
<div>Sooner or later, if nobody else proposes it, I will.</div><div><br cla=
ss=3D""></div></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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
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 />

--Apple-Mail=_DD0B3623-5087-4177-B5D5-58D786462855--

.
