This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] Algorithms vs operator* and operator==


Joe Buck wrote:

On Sun, Nov 07, 2004 at 11:40:03AM +0000, chris jefferson wrote:


Also, in the case of algorithms, I'm not convinced that move symantices would help that much.



Maybe. However, in the case of vector<T>, the special case of move semantics corresponding to "relocatable by shallow copy" helps *a lot*. Insertion, erasure, and resizing can all be done with memmove.



Looking at the classes I have access to, the most efficent way of implementing (2) looks like it is usually either just doing x=y, or doing swap(x,y). therefore move symantics are overkill for this when you simply want to either do swap(x,y) or x=y.



swap is just what you want when the algorithm calls for a swap. If the
algorithm calls for, say, copy construction followed by destruction, it
just so happens that swap can be abused in many cases to "swap" the
initialized and the uninititalized object, but it's wasteful compared to memmove and it's unsafe as well.




This is true :) I should have thought more widely than my specific interest (which is the contents of <algorithm>, where most algorithms can be implemented by simply performing alot of swaps, but we "optimise" using copying in some cases, for example to do insertion sorts.

What I would like to be able to do is to have a new type trait, and
specialize std::vector on this trait. If the property holds, the
specialized vector would do resizing, insertion, and erasure by
memmove'ing the surviving elements. I don't think that this would be
excessively complicated to implement. I would then give all of the
standard containers and std::string the appropriate trait.


This also relates back to some discussions about memoryness, where if you can use memmove, then we could be using realloc (or some variant of it) to do the moving. It's worth noting that realloc, even when it requires moving, can be much more efficent on some operating systems (such as linux), because in some cases it can simply fiddle with the memory table rather than actually undertaking a copy operation.

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]