comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Ada containers and custom allocators
Date: Wed, 09 Jan 2008 16:58:22 -0500
Date: 2008-01-09T16:58:22-05:00	[thread overview]
Message-ID: <wccy7ayk6f5.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 15hfjzq5cr38z.8ffcg9kk0ibm.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On Wed, 09 Jan 2008 10:29:46 -0500, Robert A Duff wrote:
>> Some_Ptr'Storage_Pool might be a special pool tuned for the fact that
>> Size_In_Storage_Elements = 4 and Alignment = 4.  Allocate could
>> add 4 to a known-aligned pointer, and ignore the
>> Size_In_Storage_Elements and Alignment parameters.
>> 
>> If Boo uses this pool for something other than Integer,
>> it might not work.
>
> Which is broken then. Because it does not fulfill the contract of
> Storage_Pool'Class.

What's the contract of Storage_Pool'Class?  It is certainly not intended
that all pools must support all sizes and alignments -- that would
defeat the optimization purpose of pools.

>...I guess that Allocate is allowed to raise
> Storage_Error, but not to ignore parameters.

Well, if it ignores the size, or raises an exception when the size is
not 4, either way, it won't work when the size is not 4.  But I agree
that an exception is better.  I'd like to suppress that check, though,
if it's too slow.

> If the implementation handles a family of pools one per object's size power
> of two or like that, then it should return the family root rather than the
> size-specific pool.

What if there is no such root?  How about an implementation that creates
one pool for each static size that is used in the program, up to 100
bytes.  Any access type whose designated type's size is nonstatic,
or > 100, uses a separate pool that can handle any size, and does
not call those static-size pools.  Each static-size pool has the
size built in to its code.

Sounds like an efficient implementation.  When you say "new Integer",
there's no need to check the size at run time, because the compiler
knows it's 4.  Do you think this implementation is wrong?

>...Otherwise, the following will work either:
>
> type Integer_Ptr is access Integer;
> type Character_Ptr is access Character;
> for Character_Ptr'Storage_Pool use Integer_Ptr'Storage_Pool;

I don't think the RM requires the above to work properly.

> I think ARM should clarify the issue of how pools could be constrained
> while allowing a safe use.

Perhaps.

>> However, I see nothing wrong with having a predefined operation that
>> returns a suitable pool.
>
> Yes. 

- Bob



  reply	other threads:[~2008-01-09 21:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-07 15:48 Ada containers and custom allocators Maciej Sobczak
2008-01-07 16:29 ` Dmitry A. Kazakov
2008-01-08  1:54 ` Randy Brukardt
2008-01-08  7:59   ` Maciej Sobczak
2008-01-08 23:54     ` Randy Brukardt
2008-01-09  8:56       ` Dmitry A. Kazakov
2008-01-09 15:29         ` Robert A Duff
2008-01-09 17:09           ` Dmitry A. Kazakov
2008-01-09 21:58             ` Robert A Duff [this message]
2008-01-10 10:12               ` Dmitry A. Kazakov
2008-01-11  5:00           ` Randy Brukardt
2008-01-09 15:28       ` Robert A Duff
2008-01-11  5:00         ` Randy Brukardt
2008-01-11 21:02           ` Maciej Sobczak
2008-01-11 22:41             ` Robert A Duff
2008-01-12 13:40               ` Maciej Sobczak
2008-01-12 15:59                 ` Robert A Duff
2008-01-09  1:17     ` Jeffrey R. Carter
replies disabled

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