[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Request to add *-resize! functions for contiguous mutable data struc

From: Taylan Kammer
Subject: Re: Request to add *-resize! functions for contiguous mutable data structures.
Date: Sat, 7 Aug 2021 12:31:09 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0

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! <bytevector> new-size [fill])
> (vector-resize! <vector> 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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]