2

I would like to know if the Element_Type object is stored within a Hashmap in Ada (either a normal Hashmap, indefinite or bounded) as is or it is only stored a pointer to the instance of the real Element_Type object, that is, I want to be sure that the elements are not copied into the hashmap.

Albatros23
  • 297
  • 2
  • 14
  • 1
    No, elements are copied into the map, but they can be updated in-place when they've been added. – egilhh May 26 '21 at 10:17
  • 1
    If you are using the GNAT Ada toolset, the whole run-time is itself written in Ada. From GNAT Studio, you can study how it is implemented with a few right-clicks. – Zerte May 26 '21 at 11:58
  • 2
    Since it’s possible to store the value of an expression, there’s no chance of having a pointer to the external object; there needn’t be an external object. – Simon Wright May 26 '21 at 12:54
  • 3
    Why do you care? – Jeffrey R. Carter May 27 '21 at 09:15
  • @JeffreyR.Carter I'm writting an observer design pattern and I want to store singletons of the observers, but if the elements are being copied I could run out of memory and I could not have the last version of the observer which I have to notify, so I think I have to store the pointers to the observers class-wide concrete observer in order to achieve that. – Albatros23 May 28 '21 at 07:37
  • Many of the "design patterns" aren't design patterns at all; they're work-arounds for the limitations of the languages used by the authors. For example, the singleton pattern is a work-around for the lack of modules; in Ada, a singleton is simply a package. In my experience, following the design pattern approach usually results in poor Ada. – Jeffrey R. Carter May 28 '21 at 08:28
  • 1
    As additional examples of @JeffreyR.Carter's point, examine these [_Software Patterns Implemented in Ada_](http://adapower.com/index.php?Command=Class&ClassID=Patterns&Title=Patterns) – trashgod May 28 '21 at 20:20

0 Answers0