From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: dynamic vs static tasks allocation Date: Thu, 16 Oct 2014 11:45:34 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 16 Oct 2014 18:45:32 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="206f88a41f45fc94d25d07d064d738e2"; logging-data="14757"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/HmoZvgjrb9l0P7Px23Y9QvNqxfntamRQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 In-Reply-To: Cancel-Lock: sha1:GMBSMbmYvsRb9SMOfaoHFqNJr+4= Xref: news.eternal-september.org comp.lang.ada:22535 Date: 2014-10-16T11:45:34-07:00 List-Id: On 10/16/2014 10:25 AM, Stribor40 wrote: > If you know ahead of time how many tasks will be needed is it better to > create tasks dynamically with new operator or just statically? > > Which is way is recommended and why even bother allocating dynamically? There are actually 3 ways to create tasks: 1. Statically, in a pkg or the main procedure: package body P is task Foo is 2. Dynamically without access types, using block statements or subprograms: task type Foo; type Foo_List is array (Positive range <>) of Foo; procedure P (Num_Workers : in Positive) is Worker : Foo_List (1 .. N); 3. Dynamically with access types, using new: task type Foo; type Foo_Ptr is access Foo; Worker : Foo_Ptr; ... Worker := new Foo; 1 and 2 are often both considered static allocation. The trouble with 3, as with any use of access types, is memory management. With access-to-task types, you also have to be sure the task has terminated before freeing it. For these reasons, I avoid 3 whenever possible. -- Jeff Carter "I blow my nose on you." Monty Python & the Holy Grail 03