comp.lang.ada
 help / color / mirror / Atom feed
From: "Sergey Koshcheyev" <serko84@hotmail.com>
Subject: Re: Specialization
Date: Fri, 31 May 2002 07:41:27 +0200
Date: 2002-05-31T07:41:27+02:00	[thread overview]
Message-ID: <ad72e5$e9c$1@ns.felk.cvut.cz> (raw)
In-Reply-To: 3CF6CF7D.8000704@worldnet.att.net


"Jim Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
news:3CF6CF7D.8000704@worldnet.att.net...
> Baugereau wrote:
> > Ok so this is the difference of philosophy with STL's vector, which is
plain
> > value-oriented.
> > What I dislike here is the lack of locality of the elements, and the
need to
> > "new" every time I add an element...
> > Any comment?
>
> The difference is that in C++ you "new" the element before you add
> it to the vector (in the constructor).

This is wrong, if you have a vector<BigObject> in C++ STL, then what is
stored are BigObjects, not pointers to them. There are a few tricks that can
be used to achieve this ("placement new", and also the fact that it is
possible to call object destructors manually).

> If you were to dynamically allocate all your objects in Ada, just as
> you do in C++, then the container would not need to perform any of the
> dynamic allocation. You could simply add references to the objects
> just like you do in C++.

When using STL containers, you can add a local object into the container,
for example, and it will be properly copied.

> You will also find that Ada scoping rules are much more strict than C++
> scoping rules. This can influence the way you design your container
> package.

The scoping rules are not the problem, I think. You can copy the objects, if
needed. To imitate C++ in this respect, you just need some way (possibly, a
hack) to manually Initialize and Finalize the inserted objects, and ensure
that the compiler doesn't also try to do that. Maybe playing with
Storage_Pools a little will lead to a solution. Or maybe there is a more
Ada-like way, I don't know.

Sergey.





  reply	other threads:[~2002-05-31  5:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-30 12:39 Specialization Baugereau
2002-05-30 17:09 ` Specialization Ted Dennison
2002-05-30 17:29   ` Specialization Baugereau
2002-05-30 19:20     ` Specialization Stephen Leake
2002-05-30 19:48       ` Specialization Baugereau
2002-05-31  1:18         ` Specialization Jim Rogers
2002-05-31  5:41           ` Sergey Koshcheyev [this message]
2002-05-31 11:36             ` Specialization Baugereau
2002-05-31 14:08             ` Specialization Jim Rogers
2002-05-31 16:45               ` Specialization Hyman Rosen
2002-05-31 17:05               ` Specialization Sergey Koshcheyev
2002-05-31 17:40                 ` Specialization Hyman Rosen
2002-05-31 20:04                   ` Specialization Sergey Koshcheyev
2002-05-31 21:25                     ` Specialization Hyman Rosen
2002-05-31 13:27         ` Specialization Stephen Leake
2002-05-31 19:46           ` Specialization Simon Wright
2002-06-01 15:30             ` Specialization Stephen Leake
2002-05-31 19:44   ` Specialization Simon Wright
2002-06-01 15:25     ` Specialization Stephen Leake
2002-06-01 17:12       ` Specialization Simon Wright
2002-06-01 19:50         ` Specialization Stephen Leake
2002-05-30 17:46 ` Specialization Toshitaka Kumano
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox