Re: Dynamic Array reserve

2017-12-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/17/17 11:18 AM, Vino wrote: On Sunday, 17 December 2017 at 00:45:06 UTC, Ali Çehreli wrote: On 12/16/2017 03:58 PM, Steven Schveighoffer wrote: [...] I was going to suggest the same to Vino and I was writing the following program to demonstrate how low the number of allocations is.

Re: Dynamic Array reserve

2017-12-17 Thread Vino via Digitalmars-d-learn
On Sunday, 17 December 2017 at 00:45:06 UTC, Ali Çehreli wrote: On 12/16/2017 03:58 PM, Steven Schveighoffer wrote: [...] I was going to suggest the same to Vino and I was writing the following program to demonstrate how low the number of allocations is. [...] Hi Steven /Ali,

Re: Dynamic Array reserve

2017-12-16 Thread Ali Çehreli via Digitalmars-d-learn
On 12/16/2017 03:58 PM, Steven Schveighoffer wrote: I think you are fine to just use Array and not worry about the reallocations, they are handled automatically. -Steve I was going to suggest the same to Vino and I was writing the following program to demonstrate how low the number of

Re: Dynamic Array reserve

2017-12-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/16/17 5:48 PM, Vino wrote: On Saturday, 16 December 2017 at 16:46:49 UTC, Jacob Carlborg wrote: On 2017-12-16 15:11, Vino wrote: Hi All,   Request your help on reserve an dynamic array when the capacity is reached to a point(eg: 80%) so the array to extend the reserve by next 20%

Re: Dynamic Array reserve

2017-12-16 Thread Vino via Digitalmars-d-learn
On Saturday, 16 December 2017 at 16:46:49 UTC, Jacob Carlborg wrote: On 2017-12-16 15:11, Vino wrote: Hi All,  Request your help on reserve an dynamic array when the capacity is reached to a point(eg: 80%) so the array to extend the reserve by next 20% Example: Array!string Test; Test.

Re: Dynamic Array reserve

2017-12-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-12-16 15:11, Vino wrote: Hi All,  Request your help on reserve an dynamic array when the capacity is reached to a point(eg: 80%) so the array to extend the reserve by next 20% Example: Array!string Test; Test. reserve(100) - Initall Test =(.) - The number of entries are

Dynamic Array reserve

2017-12-16 Thread Vino via Digitalmars-d-learn
Hi All, Request your help on reserve an dynamic array when the capacity is reached to a point(eg: 80%) so the array to extend the reserve by next 20% Example: Array!string Test; Test. reserve(100) - Initall Test =(.) - The number of entries are dynamic if (array.capacity > 80%) {

Re: Garbage Collector profiling and the dynamic array reserve() function

2017-10-22 Thread bauss via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 15:39:43 UTC, Steven Schveighoffer wrote: On 10/18/17 1:40 AM, Tony wrote: On Tuesday, 17 October 2017 at 13:27:24 UTC, Steven Schveighoffer wrote: I don't know what "allocations" represents, but reserve actually calls gc_malloc, and the others do not (the

Re: Garbage Collector profiling and the dynamic array reserve() function

2017-10-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/18/17 1:40 AM, Tony wrote: On Tuesday, 17 October 2017 at 13:27:24 UTC, Steven Schveighoffer wrote: I don't know what "allocations" represents, but reserve actually calls gc_malloc, and the others do not (the space is available to expand into the block). There should be only one

Re: Garbage Collector profiling and the dynamic array reserve() function

2017-10-17 Thread Tony via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 13:27:24 UTC, Steven Schveighoffer wrote: I don't know what "allocations" represents, but reserve actually calls gc_malloc, and the others do not (the space is available to expand into the block). There should be only one allocation IMO. -Steve So there

Re: Garbage Collector profiling and the dynamic array reserve() function

2017-10-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/17/17 2:14 AM, Tony wrote: Found this unanswered question on StackOverflow. This program: import std.stdio; void add(ref int[] data) {     data ~= 1;     data ~= 2; } void main() {     int[] a;     writeln("capacity:",a.capacity);     auto cap = a.reserve(1000); // allocated may

Garbage Collector profiling and the dynamic array reserve() function

2017-10-17 Thread Tony via Digitalmars-d-learn
Found this unanswered question on StackOverflow. This program: import std.stdio; void add(ref int[] data) { data ~= 1; data ~= 2; } void main() { int[] a; writeln("capacity:",a.capacity); auto cap = a.reserve(1000); // allocated may be more than requested assert(cap