From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=BAYES_05,FREEMAIL_FROM, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:a05:620a:21c2:b0:6fe:b9de:2eca with SMTP id h2-20020a05620a21c200b006feb9de2ecamr227147qka.176.1674425271988; Sun, 22 Jan 2023 14:07:51 -0800 (PST) X-Received: by 2002:a05:6871:4081:b0:15e:e2af:b270 with SMTP id kz1-20020a056871408100b0015ee2afb270mr2073439oab.151.1674425271684; Sun, 22 Jan 2023 14:07:51 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 22 Jan 2023 14:07:51 -0800 (PST) In-Reply-To: <3db6b678-5a45-4b4d-9f6c-e4933b04d6c2n@googlegroups.com> Injection-Info: google-groups.googlegroups.com; posting-host=157.143.56.236; posting-account=Wbe3fAoAAAALa8UT9MWTy6mw2ahlRJms NNTP-Posting-Host: 157.143.56.236 References: <9c7cccd9-733f-49a8-b482-087ccb14b58dn@googlegroups.com> <3db6b678-5a45-4b4d-9f6c-e4933b04d6c2n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Real_Arrays on heap with overloaded operators and clean syntax From: Jim Paloander Injection-Date: Sun, 22 Jan 2023 22:07:51 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:64849 List-Id: > > Dear ADA lovers,=20 > > with stack allocation of Real_Vector ( 1 .. N ) when N >=3D 100,000 I g= et STACK_OVERFLOW ERROR while trying to check how fast operator overloading= is working for an expression=20 > >=20 > > X :=3D A + B + C + C + A + B, where=20 > > A,B,C,X are all Real_Vector ( 1 .. N ).=20 > >=20 > > So my only option was to allocate on the heap using new. But then I los= t the clean syntax=20 > >=20 > > X :=3D A + B + C + C + A + B=20 > >=20 > > and I had to write instead:=20 > >=20 > > X.all :=3D A.all + B.all + C.all + C.all + A.all + B.all.=20 > >=20 > > This is really ugly and annoying because when you are using Real_Arrays= for implementing some linear algebra method who relies heavilly on matrix = vector products and vector updates, you do need to allocate on the heap (si= zes are determined in runtime) and you do need a clean syntax. So, is there= any way to simplify my life without using the .all or even without declari= ng A,B,C,X as access Real_Vector?=20 > > Thanks for your time! > Easiest solution is probably to declare a new task and specify the stack = size using the Storage_Size aspect. Allocate as much stack space as you nee= d to be able to do the calculations and do all the allocations on the decla= red task, not on the environment task. You will avoid the unnecessary heap = allocations and have nice clean syntax.=20 >=20 > Best regards,=20 > Joakim Thank you for your reply,=20 since I am a newbie I was under the impression that tasks are used only whe= n you want to write a parallel code that takes advantage of multicore archi= tectures. You suggest I have a single task and single thread something like= this? I see, but there should be a way to do this also for the main progra= m. But thanks anyway. Are you aware of any libraries similar to Real_Arrays= , but who allocated memory internally using heap? This is the natural way t= o do such things. Similarly to the Containers.Vector. But Vector has such a= n awful syntax. There should be something like an indexer [i] similarly to = the C++ std::vector to make things simpler and overloaded operators similar= ly to Real_Arrays. It is a no brainer. Most programs need to allocate on th= e heap, why did they restrict Real_Arrays on the stack?