On Wed, 2006-09-27 at 01:29 +1000, skaller wrote:

> 
> It's really NOT clear how to make this all work properly,
> which is one reason why the development of extensible
> arrays in Felix is stalled. It isn't so hard to make
> it work for Felix objects. But for opaque C++ objects,
> extra information is required .. I'm not sure what,
> or even if it is possible to provide it.

One possible solution is to fudge the array implementation
depending on the type of element.

If the element is a well behaved Felix type, we can use
mmap/realloc trickery. We just defined 'remap' to be a
nop, move is then just memcpy + remap and finalise source,
and copy remains the C++ copy constructor.

If the type is 'opaque' and no user defined 'remap'
is provided for the type, then we don't allow it
to be remapped: we trick the array into using 
copy semantics like STL vector instead.

That is, we can still use mmap to map backing
store into pre-allocated address space, which is
better than STL vector can do, since it has to
map the backing store in instantly you say 'reserve()'
whereas we can map on demand.

But when the address space is exhausted we revert
to making a new extent, and copy the old array into
it then delete the old array. The new extent can still
be address space not virtual memory, which means
we can probably afford to allocate a lot more than
STL vector can, and avoid more copies than STL vector can,
without wasting store -- we do waste address space though.

The native Felix array is faster, because it can do
a remap. 

To see how much faster .. and it is MUCH MUCH faster ..
consider an array of trees. Copying requires copying
whole trees for each element, then deleting the source
tree. Remapping only requires adjusting uplinks
to the moved head node of the tree (if there are any).

In this case, move would be quite fast, if C++ had it,
but it would still be memcpy'ing the head nodes.

Note that using mmap is a cheat.
Our mmaped array is REALLY a trie of buckets.
This should be handled by user instructions NOT the
operating system page manager  .. but since it is there
we have to use it ;(


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to