Re: How to delete dynamic array ?

2021-03-25 Thread mw via Digitalmars-d-learn
On Tuesday, 16 March 2021 at 23:49:00 UTC, H. S. Teoh wrote: On Tue, Mar 16, 2021 at 11:28:00PM +, mw via Digitalmars-d-learn wrote: [...] suppose: double[] data; // D type: dynamic array As of 2021 what's the correct way to allocate and deallocate (free memory to the system immediatel

Re: How to delete dynamic array ?

2021-03-19 Thread Kagamin via Digitalmars-d-learn
On Thursday, 18 March 2021 at 17:57:30 UTC, Patrick Schluter wrote: It's important to understand that [] is just a practical syntax for a fat pointer. Thinking of [] just as a fancy pointer helps imho to clarify that the pointed to memory nature is independant of the pointer itself. I think

Re: How to delete dynamic array ?

2021-03-18 Thread Vinod K Chandran via Digitalmars-d-learn
On Thursday, 18 March 2021 at 21:21:37 UTC, Paul Backus wrote: The source code is here: https://github.com/p0nce/d-idioms/ Thanks for the answer. But it's more complex than I thought. Something like Latex was in my mind.

Re: How to delete dynamic array ?

2021-03-18 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 18 March 2021 at 18:48:26 UTC, Vinod K Chandran wrote: On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: I made this article to clear up that point: https://p0nce.github.io/d-idioms/#Slices-.capacity,-the-mysterious-property Sorry for this off-topic question.

Re: How to delete dynamic array ?

2021-03-18 Thread Vinod K Chandran via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: I made this article to clear up that point: https://p0nce.github.io/d-idioms/#Slices-.capacity,-the-mysterious-property Sorry for this off-topic question. I am amazed with eye catchy look of that d-idioms page. I want to cr

Re: How to delete dynamic array ?

2021-03-18 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 16:20:06 UTC, Steven Schveighoffer wrote: It's important to understand that [] is just a practical syntax for a fat pointer. Thinking of [] just as a fancy pointer helps imho to clarify that the pointed to memory nature is independant of the pointer itself.

Re: How to delete dynamic array ?

2021-03-17 Thread Ali Çehreli via Digitalmars-d-learn
On 3/17/21 10:21 AM, jmh530 wrote: > That's a little advanced, I think. And you also have > http://ddili.org/ders/d.en/slices.html > saying that slices are just another name for dynamic arrays. I don't fully agree with myself there. :) Slices are interfaces to many different kinds of consecutiv

Re: How to delete dynamic array ?

2021-03-17 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 16:32:28 UTC, Ali Çehreli wrote: On 3/17/21 3:54 AM, jmh530 wrote: On Tuesday, 16 March 2021 at 23:49:00 UTC, H. S. Teoh wrote: double[] data; data = cast(double[]) malloc(n * double.sizeof)[0 .. n]; This is one of those things that is not explained w

Re: How to delete dynamic array ?

2021-03-17 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 16:20:06 UTC, Steven Schveighoffer wrote: [snip] I've had online battles about this terminology, and people asked me to change my array article to disavow this distinction, but I'm not going to change it. It's so much easier to understand. -Steve I'll be on

Re: How to delete dynamic array ?

2021-03-17 Thread Ali Çehreli via Digitalmars-d-learn
On 3/17/21 3:54 AM, jmh530 wrote: On Tuesday, 16 March 2021 at 23:49:00 UTC, H. S. Teoh wrote: double[] data; data = cast(double[]) malloc(n * double.sizeof)[0 .. n]; This is one of those things that is not explained well enough. I have something here: http://ddili.org/ders/d.en

Re: How to delete dynamic array ?

2021-03-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/17/21 12:06 PM, jmh530 wrote: On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: On Wednesday, 17 March 2021 at 10:54:10 UTC, jmh530 wrote: This is one of those things that is not explained well enough. Yes. I made this article to clear up that point: https://p0nce.gi

Re: How to delete dynamic array ?

2021-03-17 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: On Wednesday, 17 March 2021 at 10:54:10 UTC, jmh530 wrote: This is one of those things that is not explained well enough. Yes. I made this article to clear up that point: https://p0nce.github.io/d-idioms/#Slices-.capacity,-

Re: How to delete dynamic array ?

2021-03-17 Thread frame via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: On Wednesday, 17 March 2021 at 10:54:10 UTC, jmh530 wrote: This is one of those things that is not explained well enough. I want just to add, case 3 is wrong usage. Right one is: GC.free(GC.addrOf(ar.ptr));

Re: How to delete dynamic array ?

2021-03-17 Thread Guillaume Piolat via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 10:54:10 UTC, jmh530 wrote: This is one of those things that is not explained well enough. Yes. I made this article to clear up that point: https://p0nce.github.io/d-idioms/#Slices-.capacity,-the-mysterious-property "That a slice own or not its memory is purel

Re: How to delete dynamic array ?

2021-03-17 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 16 March 2021 at 23:49:00 UTC, H. S. Teoh wrote: [snip] Note that T[] is just a slice, not the dynamic array itself. The dynamic array is allocated and managed by the GC when you append stuff to it, or when you create a new array with `new` or an array literal. None of the latte

Re: How to delete dynamic array ?

2021-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 16, 2021 at 11:28:00PM +, mw via Digitalmars-d-learn wrote: [...] > 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? [...] Note that T[] is just a

Re: How to delete dynamic array ?

2021-03-16 Thread mw via Digitalmars-d-learn
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 bat

Re: How to delete dynamic array ?

2013-12-30 Thread Jakob Ovrum
On Monday, 30 December 2013 at 06:52:20 UTC, Ilya Yaroshenko wrote: case 1: delete ar; case 2: ar.destroy(); case 3: GC.free(ar.ptr); case 4: ar = null;// (assumed that ar is only one pointer to the same array) What is the difference? How to free memory to the system immediately? It dep

Re: How to delete dynamic array ?

2013-12-30 Thread Dicebot
Answer will make more sense if ar is assumed to be any heap-allocated object, not just dynamic array. On Monday, 30 December 2013 at 06:52:20 UTC, Ilya Yaroshenko wrote: case 1: delete ar; Deprecated. Used to call destructor and GC.free after that case 2: ar.destroy(); Current solution

Re: How to delete dynamic array ?

2013-12-30 Thread bearophile
Ilya Yaroshenko: case 1: delete ar; It's deprecated. case 4: ar = null;// (assumed that ar is only one pointer to the same array) It's the simpler way. How to free memory to the system immediately? What is your use case? Bye, bearophile

How to delete dynamic array ?

2013-12-29 Thread Ilya Yaroshenko
case 1: delete ar; case 2: ar.destroy(); case 3: GC.free(ar.ptr); case 4: ar = null;// (assumed that ar is only one pointer to the same array) What is the difference? How to free memory to the system immediately? ___ Thank You & Best Regards, Ilya