Re: Often repeated array allocations

2013-07-22 Thread Namespace
On Monday, 22 July 2013 at 09:26:33 UTC, David wrote: Am 22.07.2013 10:41, schrieb Namespace: It's part of Dgame and it's the shape draw method. The method collects the vertices and give them to the vertex buffer. I will try it with my current way: static stack buffer with a size of 1024 and o

Re: Often repeated array allocations

2013-07-22 Thread Jacob Carlborg
On 2013-07-21 12:18, Namespace wrote: But then I have mostly far too much and maybe a few times a bit too less store. It's not flexible. But maybe with a smaller granule. What's about this: You said you needed between 100 and 4000 floats. My suggestion will allocate 4000 floats once per threa

Re: Often repeated array allocations

2013-07-22 Thread David
Am 22.07.2013 10:41, schrieb Namespace: > It's part of Dgame and it's the shape draw method. The method collects > the vertices and give them to the vertex buffer. > I will try it with my current way: static stack buffer with a size of > 1024 and otherwise I will temporary allocate memory. But how

Re: Often repeated array allocations

2013-07-22 Thread Namespace
It's part of Dgame and it's the shape draw method. The method collects the vertices and give them to the vertex buffer. I will try it with my current way: static stack buffer with a size of 1024 and otherwise I will temporary allocate memory. But how much shapes grow larger than 1024 vertices ;)

Re: Often repeated array allocations

2013-07-22 Thread monarch_dodra
On Sunday, 21 July 2013 at 21:35:15 UTC, Namespace wrote: On Sunday, 21 July 2013 at 21:31:08 UTC, bearophile wrote: Namespace: I have a float[1024] buffer which is used, as long as the requested size is less than 1024. If it's greater, I will temporary allocate the whole array with new float

Re: Often repeated array allocations

2013-07-21 Thread Namespace
On Sunday, 21 July 2013 at 21:31:08 UTC, bearophile wrote: Namespace: I have a float[1024] buffer which is used, as long as the requested size is less than 1024. If it's greater, I will temporary allocate the whole array with new float[Size]; That's one of the ways I solve similar problems.

Re: Often repeated array allocations

2013-07-21 Thread Dmitry Olshansky
22-Jul-2013 01:19, Namespace пишет: I really like the idea. I've changed it a bit: I have a float[1024] buffer which is used, as long as the requested size is less than 1024. If it's greater, I will temporary allocate the whole array with new float[Size]; Any improvements? Or is 1024 to small /

Re: Often repeated array allocations

2013-07-21 Thread bearophile
Namespace: I have a float[1024] buffer which is used, as long as the requested size is less than 1024. If it's greater, I will temporary allocate the whole array with new float[Size]; That's one of the ways I solve similar problems. Any improvements? Or is 1024 to small / big? An idea is

Re: Often repeated array allocations

2013-07-21 Thread Namespace
My analogy goes as follows: a chunk of memory for temporary needs => scratch pad (as in sheet of paper for quick notes/sketches). Something along the lines of: class A{ static float[] buffer; static this(){ buffer = new float[as_big_as_it_gets]; }

Re: Often repeated array allocations

2013-07-21 Thread Dmitry Olshansky
21-Jul-2013 00:42, Ali Çehreli пишет: On 07/20/2013 01:22 PM, Dmitry Olshansky wrote: > 21-Jul-2013 00:19, Namespace пишет: >> Let us assume we have a method of a class which is used often and the >> method is called periodically and must allocate every time a array >> between 100 and 4000 e

Re: Often repeated array allocations

2013-07-21 Thread Dmitry Olshansky
21-Jul-2013 00:46, Namespace пишет: On Saturday, 20 July 2013 at 20:22:56 UTC, Dmitry Olshansky wrote: 21-Jul-2013 00:19, Namespace пишет: Let us assume we have a method of a class which is used often and the method is called periodically and must allocate every time a array between 100 and 400

Re: Often repeated array allocations

2013-07-21 Thread bearophile
Namespace: I agree, but how? ;) You know by yourself that Walter & Andrei are very hard to convince by such things. I think there is only a small number of Ada ideas worth copying, like: - Integral overflows; - Ranged integers; - A library of collections allocated in-place in the standard

Re: Often repeated array allocations

2013-07-21 Thread Namespace
On Sunday, 21 July 2013 at 10:30:16 UTC, bearophile wrote: Namespace: But D isn't like Ada. But D should be a bit more like Ada, for such things :-) Bye, bearophile I agree, but how? ;) You know by yourself that Walter & Andrei are very hard to convince by such things.

Re: Often repeated array allocations

2013-07-21 Thread bearophile
Namespace: But D isn't like Ada. But D should be a bit more like Ada, for such things :-) Bye, bearophile

Re: Often repeated array allocations

2013-07-21 Thread Namespace
On Sunday, 21 July 2013 at 09:16:47 UTC, Jacob Carlborg wrote: On 2013-07-21 08:45, Namespace wrote: But D isn't like Ada. It's more like C++ and there Heap allocations is often used too. It would be really cool if we had allocators already. Something like: with (AllocatorX) { /// will use

Re: Often repeated array allocations

2013-07-21 Thread Jacob Carlborg
On 2013-07-21 08:45, Namespace wrote: But D isn't like Ada. It's more like C++ and there Heap allocations is often used too. It would be really cool if we had allocators already. Something like: with (AllocatorX) { /// will use malloc and free instead of calling the GC float[] arr;

Re: Often repeated array allocations

2013-07-20 Thread Namespace
But D isn't like Ada. It's more like C++ and there Heap allocations is often used too. It would be really cool if we had allocators already. Something like: with (AllocatorX) { /// will use malloc and free instead of calling the GC float[] arr; arr ~= 42; } And I still don't

Re: Often repeated array allocations

2013-07-20 Thread bearophile
Namespace: So, you would never allocate with float[]? Generally in D I allocate on the heap with new, and once in a while with minimallyInitializedArray. Stack-allocation is left for situations where max performance is needed. Like you have to build a tree of string distances, and you use a

Re: Often repeated array allocations

2013-07-20 Thread Namespace
On Saturday, 20 July 2013 at 21:39:31 UTC, bearophile wrote: Namespace: Yeah, but aren't 4000 elements a bit much for a stack allocated array? 4000 floats take about 16 KB. If your function is not recursive and it's not much transitively recursive, then I think it's acceptable. But how much

Re: Often repeated array allocations

2013-07-20 Thread bearophile
Namespace: Yeah, but aren't 4000 elements a bit much for a stack allocated array? 4000 floats take about 16 KB. If your function is not recursive and it's not much transitively recursive, then I think it's acceptable. But how much stack are your other functions using? You have to estimate i

Re: Often repeated array allocations

2013-07-20 Thread Namespace
On Saturday, 20 July 2013 at 20:34:50 UTC, bearophile wrote: Namespace: But I want to hear other opinions. :) D also supports alloca(), that for 1D arrays is almost bearable. See also: http://d.puremagic.com/issues/show_bug.cgi?id=9832 Bye, bearophile Yeah, but aren't 4000 elements a bit

Re: Often repeated array allocations

2013-07-20 Thread Namespace
On Saturday, 20 July 2013 at 20:22:56 UTC, Dmitry Olshansky wrote: 21-Jul-2013 00:19, Namespace пишет: Let us assume we have a method of a class which is used often and the method is called periodically and must allocate every time a array between 100 and 4000 elements. What would you do? 1.

Re: Often repeated array allocations

2013-07-20 Thread Ali Çehreli
On 07/20/2013 01:22 PM, Dmitry Olshansky wrote: > 21-Jul-2013 00:19, Namespace пишет: >> Let us assume we have a method of a class which is used often and the >> method is called periodically and must allocate every time a array >> between 100 and 4000 elements. What would you do? > 5. Keep a TL

Re: Often repeated array allocations

2013-07-20 Thread bearophile
Namespace: But I want to hear other opinions. :) D also supports alloca(), that for 1D arrays is almost bearable. See also: http://d.puremagic.com/issues/show_bug.cgi?id=9832 Bye, bearophile

Re: Often repeated array allocations

2013-07-20 Thread Dmitry Olshansky
21-Jul-2013 00:19, Namespace пишет: Let us assume we have a method of a class which is used often and the method is called periodically and must allocate every time a array between 100 and 4000 elements. What would you do? 1. Simple: float[] array; 2. Reserve: float[] array; array.reserve(N); //

Often repeated array allocations

2013-07-20 Thread Namespace
Let us assume we have a method of a class which is used often and the method is called periodically and must allocate every time a array between 100 and 4000 elements. What would you do? 1. Simple: float[] array; 2. Reserve: float[] array; array.reserve(N); /// N is a parameter value 3. Use ma