comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: General circular buffer example not tied to any specific type
Date: Sun, 5 Jul 2020 20:46:56 +0200	[thread overview]
Message-ID: <rdt76s$i8q$1@gioia.aioe.org> (raw)
In-Reply-To: lyy2nyc6tu.fsf@pushface.org

On 05/07/2020 17:36, Simon Wright wrote:
> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
> 
>> On 7/5/20 11:52 AM, Simon Wright wrote:
>>> Simon Wright <simon@pushface.org> writes:
>>>
>>>> For the Size, see ARM 13.13.2(2).
>>>
>>> 13.13.2(1.2), sorry
>>
>> That only works for elementary types. For any type, a better approach
>> is generic package Ada.Storage_IO, ARM A.9
>> (http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-A-9.html).
> 
> As you say, this has the advantage of actually working.

I see no difference. In both cases some kind of type tag need to be 
written and the object's size with it if not derived from the tag.

Whether stream Read/Write or storage elements copy is then used changes 
little.

P.S. I never used Storage_IO, I did storage pools instead.

With a ring buffer you go as follows. Make a LIFO of Storage_Elements. 
It could be a descendant of Root_Storage_Pool or else if true parent 
type is already spent (Ada has no full multiple inheritance) use an 
access discriminant in a mix-in:

    type LIFO_Pool (Buffer : not null access LIFO'Class)
       with null record;

The implementation of Allocate with reserve place in Buffer. Allocate 
already has parameter Size_In_Storage_Elements.

You should only pay attention to Alignment and to atomic kicking off old 
elements when new allocation overlaps old elements in the buffer. So the 
element sizes must be stored in the LIFO. Writing into the LIFO will become:

    procedure Push (Buffer : in out LIFO'Class S : String) is
       Pool : LIFO_Pool (Buffer'Unchecked_Access);
       type String_Ptr is access String;
       for String_Ptr'Storage_Pool use Pool;
       Ptr : String_Ptr;
    begin
       Ptr := new String'("Some text");
    end Push;

P.P.S. Beware Ada finalization design bug ARM 7.6.1 (11.1/3): no 
controlled types, also.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2020-07-05 18:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-04 17:00 General circular buffer example not tied to any specific type Daniel
2020-07-04 17:25 ` Dmitry A. Kazakov
2020-07-05  9:37   ` Simon Wright
2020-07-05  9:52     ` Simon Wright
2020-07-05 13:25       ` Jeffrey R. Carter
2020-07-05 15:36         ` Simon Wright
2020-07-05 18:46           ` Dmitry A. Kazakov [this message]
2020-07-05 19:51             ` Simon Wright
2020-07-06  8:11         ` Simon Wright
2020-07-06  8:58           ` Jeffrey R. Carter
2020-07-06 10:34             ` Simon Wright
2020-07-06 11:07               ` Dmitry A. Kazakov
2020-09-03 10:31 ` riya patel
2020-09-24  4:10 ` nimaopatel121
2020-09-24  4:39   ` J-P. Rosen
2020-09-25 14:32 ` Simon Wright
replies disabled

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