DIP 1025--Dynamic Arrays Only Shrink, Never Grow--Community Review Round 1

Dukc ajieskola at gmail.com
Mon Nov 11 12:15:23 UTC 2019


On Monday, 11 November 2019 at 11:51:09 UTC, Jonathan M Davis 
wrote:
>
> IMHO, the ability to append to a dynamic array without caring 
> whether it's backed by GC-allocated memory, malloc-ed memory, 
> stack allocated memory, or whatever is a huge benefit.

Yeah... And I definitely think all of these should continue to 
exist with the possible exception of malloced memory.

> Right now, you can pass a dynamic array that isn't backed by 
> the GC to a function, and it all just works even if the 
> function needs to do a reallocation to make the array large 
> enough. Doing so is not necessarily a bug and allows you to use 
> non-GC allocated memory where appropriate while still being 
> able to grow the array, and it does so without the code having 
> to care about what kind of memory is currently backing the 
> dynamic array.

But chances are that if you grow a malloced slice bu GC, you 
cause a memory leak, and that's what Walter is trying to solve. 
On the other hand, there should be a way for the caller to 
explicitly allow a function to grow a GC-allocated slice, without 
touching the function, and my idea does not solve that. I dunno...




More information about the Digitalmars-d mailing list