From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Taylan Kammer Newsgroups: gmane.lisp.guile.devel Subject: Re: Request to add *-resize! functions for contiguous mutable data structures. Date: Sat, 7 Aug 2021 12:31:09 +0200 Message-ID: <5de0d09e-263a-20e3-a0d0-7868593db585@gmail.com> References: <97e4262b-3ff9-1b21-35d8-45ad9d45ca99@gatech.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34082"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 To: Vijay Marupudi , guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Aug 07 12:31:43 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 1mCJcD-0008hp-Uf for guile-devel@m.gmane-mx.org; Sat, 07 Aug 2021 12:31:41 +0200 Original-Received: from localhost ([::1]:41194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCJcB-0006tb-Sg for guile-devel@m.gmane-mx.org; Sat, 07 Aug 2021 06:31:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37406) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCJbo-0006tT-74 for guile-devel@gnu.org; Sat, 07 Aug 2021 06:31:16 -0400 Original-Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:51986) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCJbm-0000DL-Mb for guile-devel@gnu.org; Sat, 07 Aug 2021 06:31:15 -0400 Original-Received: by mail-wm1-x32b.google.com with SMTP id u15so7183839wmj.1 for ; Sat, 07 Aug 2021 03:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=/T+bsz7hve3vo9GwICVnIz2hiKfooRaTaN0nOeMr/TI=; b=QXv4CSz5gGlMVjz0qMfFZxs+P2BEhx00jwNsA8p++4M9W+t2yJ7fy47m9Cr1B0SSWU prSrwk3ZCEsk8ZsrAq0qHDAK2IJ1L8u84C7DrJOxg/X1vF15pFpx4KbIPAAB+vUWuNV3 AjRMGi4aN7lSD89hVVsyORn1+8HYhRWeVNGi4hZvgGtJqGGOba/Nw1BHtOlYFrUgT4ar 4r2dVv15sCeOsfU15aCKru7VO5lZ/C2KzjLzQYa6OjMsx1BrLc+3qoQ2BhEGs9HVqPlv MX5Dvnncoyd2HffYTzpvC08QceLvBz9HB70IZSBEcIsNla81Sq3KZTp70BqAaCOnWdVi IOKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/T+bsz7hve3vo9GwICVnIz2hiKfooRaTaN0nOeMr/TI=; b=ksPug4YYzBUwvatHyPmOgdEa0R0v4KZxABPI9w/SSWR7ZAV868a7ka2UQIFSDrZqHc 7r4V3tleoReO0TPIF3Zvf2bew8nrIZbY22rWcSHvWLxImz4mGoNSgzab5CeX8t+sVsEU QtUq+89jYAlMAHUQP4O9ROOT7VVqlutzc3rIzC0xfiTaQGuxglPBBKWUa/vMUJ4b6jGi e3AnInNYEE8hp8pbGUNrJNF+Z2zmlcqmRoTx8/27rN6rveABE2rRmtFfRJtkhE9Aao7H 3teKUxecPu8Q+MGFsyb1idjwe76BmkpoEj6Sw7wZvyFjDoN6QbDz7wnTGxDvkuq5k+8C nY3w== X-Gm-Message-State: AOAM531Hj/W6PigyAWGIq2ACvrGpfWUBTmrq2B0mNuZop2t/Vq94wBz9 wBQEGDfDq9WuZq9ygc+s2gZHcXDHQhY= X-Google-Smtp-Source: ABdhPJyG3HQniJoFg3hXUBvw3WtEHChVyQOYHedvtyy92xuE4JMLb0uLWo9oos0PvAru+149DeKPrw== X-Received: by 2002:a1c:4b04:: with SMTP id y4mr7521946wma.133.1628332272621; Sat, 07 Aug 2021 03:31:12 -0700 (PDT) Original-Received: from [192.168.178.20] (b2b-109-90-125-150.unitymedia.biz. [109.90.125.150]) by smtp.gmail.com with ESMTPSA id f7sm15904760wrr.54.2021.08.07.03.31.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Aug 2021 03:31:12 -0700 (PDT) In-Reply-To: <97e4262b-3ff9-1b21-35d8-45ad9d45ca99@gatech.edu> Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=taylan.kammer@gmail.com; helo=mail-wm1-x32b.google.com 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, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:20817 Archived-At: On 06.08.2021 16:33, Vijay Marupudi wrote: > Hello! > > I was curious if Guile would be willing to provide a series of > new procedures for resizing contiguous memory regions. > > (bytevector-resize! new-size [fill]) > (vector-resize! new-size [fill]) > > 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. 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. > > Ideally, this would use libc's `realloc` to make the resize > quick, so that it can avoid data copying whenever possible. > > Regards > > Vijay Marupudi > PhD Student in Human Centered-Computing > Georgia Tech > Sounds like a good idea to me. I didn't know realloc() was a thing in C (I don't write much C) and I suppose it's not possible to implement equivalent functionality with equivalent performance purely in Scheme. I'm on vacation for the next three weeks and will try to write a patch to implement this if no one beats me to it. :-) One consideration is how this should behave in the case of bytevectors that were created from an FFI pointer. In the FFI, you provide a pointer and specify how long the bytevector should be, which means it's a memory-unsafe operation. I think it would be ideal to offer a way of forcing an in-place resize, basically overriding the formerly provided size value. That means it's also memory-unsafe, but in some cases that's what you want. -- Taylan