comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Allocated aligned arrays
Date: 27 Nov 2005 15:49:30 -0500
Date: 2005-11-27T15:49:30-05:00	[thread overview]
Message-ID: <wcc8xv924v9.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1132756111.751623.309350@g14g2000cwa.googlegroups.com

"ldb" <louis@pittpatt.com> writes:

> Thanks for all the responses. I have looked into user-defined storage
> pools, but they appear to have two very large limitations:
> 
> Can they be dynamically sized?

Yes.

A storage pool can contain anything you like.  For example, it could
have a discriminant that controls the size of an array of bytes, and you
allocate out of that array.  Or it could contain a linked list of chunks
of memory.  The chunks could be allocated from some lower-level pool.
You could use mmap to allocate the chunks.  You can control their size
however you like.  You can make a storage pool type that always
allocates on page-aligned boundaries, if you like.

This is not a problem.

> Can I only associate entire types with storage pools.. or can I
> associate individual instances of a type with different pools?

This is a problem for some applications.  You say "for T'Storage_Pool
use ..." and _all_ allocators that return type T will use that pool.  It
would be more flexible to specify the pool on each "new", but Ada does
not directly support that.

Various workarounds are possible.  It's tricky to make them task-safe.

But I thought you just wanted to make sure all objects of a certain type
are allocated at some aligned boundary.  If so, you don't need a
different pool for each object.  Just make a storage pool that always
allocates on the boundary you want, and specify that pool via "for
T'Storage_Pool use ...".  I'm not sure I understand your requirements
-- why wouldn't that work?

> In other words, I'd like to be able to allocate the storage-pool size
> at run-time, after I know the dimensions of the input.

Why do you care about the size of the pool?  It seems to me you care
about the size (and alignment) of each allocated object, and that info
is passed to the Allocate procedure.  The pool itself can be programmed
to use however much memory is required, up to the available address
space.

>... I can't really
> seem to figure out if this is even possible. And furthermore, I'd only
> like certain instances of a particular class to use that storage pool,
> not all of them (I don't want every instance of a particular variable
> in a large structure to have to use my storage pool).

Heh?  Only objects allocated with "new" will use the storage pool.
Components of a record will not -- they're just part of the record.  To
align components of a record, you can use a record rep clause, and also
make sure the whole record is properly aligned.

> Perhaps, then, using subtypes, there is a way around the second issue?
> But, again, the entire purpose of requesting aligned arrays is to
> improve the speed of the run, so any rigorous conversion function is
> essentially a killer, also.

- Bob



      parent reply	other threads:[~2005-11-27 20:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-18 21:35 Allocated aligned arrays ldb
2005-11-18 22:06 ` jimmaureenrogers
2005-11-18 22:31   ` ldb
2005-11-20 11:21     ` Martin Krischik
2005-11-18 22:51   ` Simon Wright
2005-11-18 23:03     ` ldb
2005-11-19  7:36 ` Simon Wright
2005-11-19 13:12   ` Jeff Creem
2005-11-23  0:17   ` Randy Brukardt
2005-11-23 14:28     ` ldb
2005-11-24  1:39       ` Frank J. Lhota
2005-11-27 20:49       ` Robert A Duff [this message]
replies disabled

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