From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada containers and custom allocators
Date: Thu, 10 Jan 2008 11:12:56 +0100
Date: 2008-01-10T11:12:59+01:00 [thread overview]
Message-ID: <1g2a074w0yi37.2nvyj50yfwj5.dlg@40tude.net> (raw)
In-Reply-To: wccy7ayk6f5.fsf@shell01.TheWorld.com
On Wed, 09 Jan 2008 16:58:22 -0500, in comp.lang.ada you wrote:
> "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.
But a loose contract would make storage pools unusable. Actually it depends
on the semantics of the attribute P'Storage_Pool. When the result is a
constrained (optimized) pool then indeed there will be no way to fix it.
>>...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.
Either way is bad. Storage_Error should indicate a run-time problem, while
using an inappropriate pool is just a bug, basically a type error. And it
should be Constraint_Error then.
>> 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?
It is not wrong. Wrong is when P'Storage_Pool returns a specific pool from
the family. It should return a possibly less efficient family root pool,
which has to be present (when used). If an access type is created with this
root pool, the implementation is free to choose a more specific pool
instead. If for example the object size is known to be static. But that is
an implementation detail which may not leak outside (through
P'Storage_Pool, for instance). I think it should be no problem to remove
the root pool altogether upon linking when it is never used, i.e. there
should be no any overhead.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2008-01-10 10:12 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
2008-01-10 10:12 ` Dmitry A. Kazakov [this message]
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