-
Notifications
You must be signed in to change notification settings - Fork 9
Support realloc without copying? #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think the cost of all the checks and branching is going to overwhelm any savings from not copying a few bytes of |
If you really want this then you can do it with |
@Lokathor @Amanieu |
Yes, |
@Amanieu That means though that It would be interesting to know if someone already pursued this idea and what the outcome was. I have not found much online and I have no perf data to justify an extra function. I guess this is more a question about whether it is worth checking out at all. |
If the allocator has to move your data, it is already making a separate allocation and freeing the old one. This is exactly the same as what you should do if |
Is |
It was removed because in practice no allocators supported it. |
mimalloc has So it would be good to have a way to add future support, e.g. via flags as #58 proposed. And it seems obvious to me that anything that uses mmap under the hood could support this at least in principle via |
When using
realloc
it will commonly fallback toalloc
,copy
, andfree
if growing the initial allocation is impossible (see mimalloc's realloc for an easy to read example). I think it would be useful to have a specialization ofrealloc
that would leave the copying to the user code.A good use case would be allocating a buffer for a
Vec<Option<T>>
whereNone
represents a tombstone i.e. a slot that was previously occupied but is now empty (think of PHP array or Python dict). When growing the buffer it would sometimes make sense to only copyT
s and skip the tombstones. I would expect the usage of the new function to look something like this:I do not know of an allocator interface which supports this special
realloc
operation but I thought it might be useful. The current implementations of the PHP array and Python dict do not bother withrealloc
and just usemalloc
instead.The text was updated successfully, but these errors were encountered: