From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.devel Subject: Re: Request to add *-resize! functions for contiguous mutable data structures. Date: Sat, 07 Aug 2021 13:09:42 +0200 Message-ID: <45e44ba58dbbb3b2fd3ffdeab4add4a1f7525cd4.camel@telenet.be> References: <97e4262b-3ff9-1b21-35d8-45ad9d45ca99@gatech.edu> Mime-Version: 1.0 Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-5HZ4vEPcfuo8OHfFufDf" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32599"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.34.2 To: Vijay Marupudi , guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Aug 07 13:15:40 2021 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCKIl-0008G9-OB for guile-devel@m.gmane-mx.org; Sat, 07 Aug 2021 13:15:39 +0200 Original-Received: from localhost ([::1]:59740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCKIj-0005gS-Fh for guile-devel@m.gmane-mx.org; Sat, 07 Aug 2021 07:15:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCKI5-0005gK-FD for guile-devel@gnu.org; Sat, 07 Aug 2021 07:14:57 -0400 Original-Received: from leibniz.telenet-ops.be ([2a02:1800:110:4::f00:d]:35996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCKI2-0005dp-H8 for guile-devel@gnu.org; Sat, 07 Aug 2021 07:14:56 -0400 Original-Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by leibniz.telenet-ops.be (Postfix) with ESMTPS id 4Ghfkj3Y4ZzMqg4R for ; Sat, 7 Aug 2021 13:09:49 +0200 (CEST) Original-Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by laurent.telenet-ops.be with bizsmtp id eb9m2500b0mfAB401b9nct; Sat, 07 Aug 2021 13:09:47 +0200 In-Reply-To: <97e4262b-3ff9-1b21-35d8-45ad9d45ca99@gatech.edu> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1628334587; bh=kEoe6b785mR75yX52lv9k6ihUTt44S93PKgqKu/3feA=; h=Subject:From:To:Date:In-Reply-To:References; b=YOw5oE7be3cnREQgqRFsBPit3DxqwBl0sw2ArtQNgCZ2ZcnBmRR1JJWP5b3Lq5Li3 2j77osqZcr/x8SsNehAEYxTYZ8D3iYIOOGDdR07p8YD23jQyaq4u5n5dMX/KDBLrMl i8nyaUfJOt+Y73wrsowdAzofu+oRpjjrs4ODErVi13HKbZm1vVEi83ftbQ2LcmqfO1 f5jrfI3yZjZKYsBTX5xMDi4qXACvT4MuE0sSovjU+pO9U6t9U4soDOXWImZ7F6kEXw AXiYSsr+dJxvHL2FmOjycO6Ihfe9Y7XLUSuzyKP0DPQPSquIbYCPTfmGuvtcTIvA9T u5SAOfGYHn7dg== Received-SPF: pass client-ip=2a02:1800:110:4::f00:d; envelope-from=maximedevos@telenet.be; helo=leibniz.telenet-ops.be X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20818 Archived-At: --=-5HZ4vEPcfuo8OHfFufDf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Vijay Marupudi schreef op vr 06-08-2021 om 09:33 [-0500]: > Hello! >=20 > I was curious if Guile would be willing to provide a series of > new procedures for resizing contiguous memory regions. >=20 > (bytevector-resize! new-size [fill]) > (vector-resize! new-size [fill]) >=20 > The [fill] parameter could be used if the new-size is bigger than > the current size. > > This would make writing imperative code easier and more > performant. A problem is that this prevents optimisations and can currently introduce bugs in concurrent code. Consider the following code: b.scm: (use-modules (rnrs bytevectors)) (define (bv-first-two bv) (unless (bytevector? bv) (error "not a bv")) (unless (>=3D (bytevector-length bv) 2) ; L6 (error "too small")) (values (bytevector-u8-ref bv 0) ; L8 (bytevector-u8-ref bv 1))) ; L9 bv-first-two Compile it with optimisations enabled: guild compile b.scm -o b.go -O3 && guild disassemble b.go (Unfortunately, guile cannot yet compile the bounds check at L8 and L9 away even though we performed a bounds check at L6 away.) I can't say I understand the disassembled code very well, but I do note that the bounds checks (search for (jl ...), (jnl ...) and imm-u64 I acknowledge that it is not idiomatic Scheme to use > mutable data structures, however this is useful to me for > dealing with large amounts of text data, in which I need random > access and flexible data storage. It would allow me to move off > my custom C extension vector and allow me to use other > vector-* functions. >=20 > Ideally, this would use libc's `realloc` to make the resize > quick, so that it can avoid data copying whenever possible. If you're very careful, you can use 'bytevector->pointer', 'pointer->byteve= ctor' and (foreign-library-function ... "malloc" ...), (foreign-library-function ... "realloc" ...), (foreign-library-function ... "free" ...). (ice-9 vlist) and might be interesting as = well. Greetings, Maxime. --=-5HZ4vEPcfuo8OHfFufDf Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYQ5p9hccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7q7HAP9qxpt5edXon5r3r1Eh6RkbSk+Z ayI9Sshi5U/uoKC0XwEApgXyV2C3SUMfigzA/tYEc7tDh+SKTldDYJvARd7FXAk= =maQB -----END PGP SIGNATURE----- --=-5HZ4vEPcfuo8OHfFufDf--