oldk1331 wrote:
> > More precisely, instead of building 
> > list and passing it to constructor build desired object 
> > directly.
> 
> Building the desired object through list might be faster
> than build directly -- for example, enqueue! checks if its
> argument is empty every time, that slows thing down.

Main cost is due to memory allocation.  Array version
can allocate big hunk of memory, but list-based one
pays costs of several allocations.

> > OTOH in other cases signifcant savings are 
> > obtained by sharing substructures.  But sharing works 
> > well only if we avoid destructive operations. 
> 
> But like you said in the other thread, Spad is pretty imperative,
> thus destructive operations are unavoidable, thus Spad
> (and Lisp) provides both destructive operations and non
> destructive operation.  That gives more reason to have
> a destructive version of constructor.

Well, we provide destructive operations not for love of
impeartive things but due to speed.  ATM I see no case
where destructive constructor would give us important
speedup.
 
> > Concerning idea of destructive constructor: memory is 
> > freed by garbage collector, so all we can do to free 
> > memory is to avoid keeping references to unneeded things. 
> > This means that destructive constructor can give any 
> > gain only in very special cases. 
> 
> For some data structure, I think a destructive constructor
> takes O(1) instead of O(n): for example Stack (because of
> the direct assign).  For other data structure, a destructive
> constructor can save half time and half peak memory --
> copy is O(n), we can save that step.

Sure, destructive constructor could be faster than
normal constructor.  But I see no case when:
- we care about speed of constructor
- destructive constructor gives us best space

To put it differently, if you say "see we have this
important calculation and destructive constructor
gives us better speed than alternatives", then
I will not oppose.  But I oppose intrducing destructive
constructor just because it makes some artifical
benchmark faster.
-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to