How to delete dynamic array ?

mw mingwu at gmail.com
Tue Mar 16 23:28:00 UTC 2021


On Monday, 30 December 2013 at 08:13:30 UTC, bearophile wrote:
>> How to free memory to the system immediately?
>
> What is your use case?

The use case is: we want deterministic memory management, (and 
the application data is too big to fit into memory at once, so 
have to be processed batch by batch).

suppose:

   double[] data;  // D type: dynamic array


As of 2021 what's the correct way to allocate and deallocate 
(free memory to the system immediately) D's dynamic array?

If we use core.stdc.stdlib.malloc and free, e.g.

```
   data = core.stdc.stdlib.malloc(n * double.sizeof);
   // processing ...
   free(data.ptr);
```

-- will data.length be set correctly (since it's a D type) with 
malloc?

-- or we still need to manually set data.length = n? (in this 
case, will it become GC managed, which we want to avoid in this 
app)?

Thanks.




More information about the Digitalmars-d-learn mailing list