From: Adam Beneschan <adam@irvine.com>
Subject: Re: Allocation questions
Date: Thu, 28 May 2009 07:51:50 -0700 (PDT)
Date: 2009-05-28T07:51:50-07:00 [thread overview]
Message-ID: <336b285f-2245-4ede-8528-841a2c713e80@b7g2000pre.googlegroups.com> (raw)
In-Reply-To: 78f30732-8d8d-4009-b9ed-ba19d275a5d9@f16g2000vbf.googlegroups.com
On May 28, 6:39 am, Martin <martin.do...@btopenworld.com> wrote:
> > 2 more questions:
>
> > 1) In fact (due to my background!), I would like to use the dot notation:
> > object.method.
> > So I have add "tagged":
I'm not sure I'd recommend declaring a type "tagged" JUST to get the
dot notation. There's a small amount of overhead involved with making
a type tagged; but more importantly, a fair number of language rules
are different for tagged types than for untagged types. (You ran into
one different rule below; another one that comes to mind immediately
is that there are differences in the semantics of "=". There are
others. You might not run into any of them, though.)
> > type Delay_Type (Size : Nb_Of_Samples := 0) is tagged private;
> > ...
> > private
> > type Delay_Type (Size : Nb_Of_Samples :=0) is tagged record
> > ...
>
> > When I compile, I have:
> > "discriminants of tagged type cannot have defaults"
> > How can I fix it ?
>
> Just remove the " := 0" bit.
To elaborate, the main advantage of using the default is that after
you declare an object of type Delay_Type, you can change its Size by
reassigning the whole object. If you don't need to use this feature---
i.e. if you will declare an object of type Delay_Type(Size=>N) and
then never change the Size of that object afterwards---then I don't
think there's any need to use the default.
> > 2) If Nb_Of_Samples range is too large, around 1..5_000_000, I have a
> > nice Segmentation fault. How can I fix that ?
As Xavier pointed out, using a default could cause a lot larger array
to be allocated (because the Size could be changed later). If you
remove the default, this problem may go away on its own. I don't see
how an array of five million floats would cause a problem. (Not these
days, anyway. Back when I used to work on a mainframe that took up a
whole room and had a whopping ONE MEGABYTE of RAM, maybe it would have
been a problem. I also used to put my COBOL programs on punch cards
and walk five miles to school, uphill both ways...)
-- Adam
next prev parent reply other threads:[~2009-05-28 14:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-28 9:46 Allocation questions Olivier Scalbert
2009-05-28 10:02 ` Martin
2009-05-28 11:55 ` xavier grave
2009-05-28 12:19 ` Ludovic Brenta
2009-05-28 13:00 ` Georg Bauhaus
2009-05-28 23:13 ` Robert A Duff
2009-05-28 10:05 ` Dmitry A. Kazakov
2009-05-28 10:40 ` Martin
2009-05-28 12:32 ` Olivier Scalbert
2009-05-28 13:39 ` Martin
2009-05-28 13:57 ` Olivier Scalbert
2009-05-28 14:51 ` Adam Beneschan [this message]
2009-05-28 17:58 ` Randy Brukardt
2009-05-28 14:04 ` Dmitry A. Kazakov
2009-05-28 16:59 ` Jeffrey R. Carter
2009-05-28 17:26 ` Olivier Scalbert
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox