Re: What's the point of static arrays ?

2020-07-13 Thread wjoe via Digitalmars-d-learn
On Friday, 10 July 2020 at 21:24:08 UTC, Ali Çehreli wrote: What is important is overhead: That's the major point I took from all this. Thanks for your effort. And thanks everybody else, too, I really appreciate it.

Re: What's the point of static arrays ?

2020-07-10 Thread Ali Çehreli via Digitalmars-d-learn
On 7/10/20 8:03 AM, wjoe wrote: > What I'm saying is even if this allocation is slow let's say 5ms, but it > only happens once, that wouldn't matter to overall performance at all. Yes, you are correct and there are dynamic arrays that are allocated once in many programs. I haven't read the

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
On Friday, 10 July 2020 at 14:20:15 UTC, wjoe wrote: On Friday, 10 July 2020 at 10:47:49 UTC, psycha0s wrote: On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: A static array resides in this memory (with a fixed length, so a length needn't be stored because bounds can be checked at compile

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
On Friday, 10 July 2020 at 11:13:51 UTC, Stanislav Blinov wrote: On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: So many awesome answers, thank you very much everyone! Less overhead, Using/needing it to interface with something else, and Efficiency are very good points. However stack

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
On Friday, 10 July 2020 at 10:47:49 UTC, psycha0s wrote: On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: However stack memory needs to be allocated at program start. I don't see a huge benefit in allocation speed vs. heap pre-allocation, or is there? I mean 1 allocation vs 2 isn't going

Re: What's the point of static arrays ?

2020-07-10 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: However stack memory needs to be allocated at program start. I don't see a huge benefit in allocation speed vs. heap pre-allocation, or is there? I mean 1 allocation vs 2 isn't going to noticeably improve overall performance. You seem to

Re: What's the point of static arrays ?

2020-07-10 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: So many awesome answers, thank you very much everyone! Less overhead, Using/needing it to interface with something else, and Efficiency are very good points. However stack memory needs to be allocated at program start. I don't see a huge

Re: What's the point of static arrays ?

2020-07-10 Thread psycha0s via Digitalmars-d-learn
On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote: However stack memory needs to be allocated at program start. I don't see a huge benefit in allocation speed vs. heap pre-allocation, or is there? I mean 1 allocation vs 2 isn't going to noticeably improve overall performance. Allocation on

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
On Thursday, 9 July 2020 at 17:15:26 UTC, Jonathan M Davis wrote: On Thursday, July 9, 2020 10:21:41 AM MDT H. S. Teoh via Digitalmars-d-learn wrote: > - Assignment copies the whole array, as in int[5] a; auto b > = a; Sometimes this is desirable. Consider the 3D game example. Suppose

Re: What's the point of static arrays ?

2020-07-10 Thread wjoe via Digitalmars-d-learn
So many awesome answers, thank you very much everyone! Less overhead, Using/needing it to interface with something else, and Efficiency are very good points. However stack memory needs to be allocated at program start. I don't see a huge benefit in allocation speed vs. heap pre-allocation, or

Re: What's the point of static arrays ?

2020-07-09 Thread IGotD- via Digitalmars-d-learn
On Thursday, 9 July 2020 at 18:51:47 UTC, Paul Backus wrote: Note that using VLAs in C is widely considered to be bad practice, and that they were made optional in the C11 standard. If you want to allocate an array on the stack, the best way is to use a static array for size below a

Re: What's the point of static arrays ?

2020-07-09 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 9 July 2020 at 18:02:02 UTC, IGotD- wrote: Static arrays are great because as already mentioned, they are allocated on the stack (unless it is global variable something, then it ends up in the data segment or TLS area). As C/C++ now allows dynamically sized static arrays (for

Re: What's the point of static arrays ?

2020-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 09, 2020 at 06:02:02PM +, IGotD- via Digitalmars-d-learn wrote: [...] > Is this the reason that ubyte[arraySize] doesn't create a dynamic > array with size arraySize? > > Now you need to do. > > ubyte[] arr; > arr.length = arraySize; Nah, just do this: arr = new

Re: What's the point of static arrays ?

2020-07-09 Thread IGotD- via Digitalmars-d-learn
On Thursday, 9 July 2020 at 12:12:06 UTC, wjoe wrote: ... Static arrays are great because as already mentioned, they are allocated on the stack (unless it is global variable something, then it ends up in the data segment or TLS area). As C/C++ now allows dynamically sized static arrays

Re: What's the point of static arrays ?

2020-07-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 9, 2020 10:21:41 AM MDT H. S. Teoh via Digitalmars-d-learn wrote: > > - Assignment copies the whole array, as in int[5] a; auto b = a; > > Sometimes this is desirable. Consider the 3D game example. Suppose > you're given a vector and need to perform some computation on it. If

Re: What's the point of static arrays ?

2020-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 09, 2020 at 12:12:06PM +, wjoe via Digitalmars-d-learn wrote: > + The size is known at compile time. > > vs. > > - Can neither grow nor shrink them > - Can't append elements > - Can't remove elements Consider a 3D game in which you represent vectors as static arrays of 4

Re: What's the point of static arrays ?

2020-07-09 Thread Ali Çehreli via Digitalmars-d-learn
On 7/9/20 5:12 AM, wjoe wrote: Considering the many downsides why would I ever want to choose a static over a dynamic array ? In addition to what others said, dynamic arrays can be more expensive both in space and time. Time: Dynamic array elements are accessed through an extra pointer

Re: What's the point of static arrays ?

2020-07-09 Thread psycha0s via Digitalmars-d-learn
On Thursday, 9 July 2020 at 12:12:06 UTC, wjoe wrote: Also GC but it's possible to make a dynamic array implementation which avoids the GC. It's easy to make a dynamic array without using the GC. Did you mean "implementation which avoids memory management"? I'm not considering supposed

Re: What's the point of static arrays ?

2020-07-09 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 9 July 2020 at 12:12:06 UTC, wjoe wrote: I'm not considering supposed performance benefits/penalties because these need to be profiled. Considering the many downsides why would I ever want to choose a static over a dynamic array ? Simply put: static arrays are not dynamic