Re: how not use memmove when insert a object in the list
- From: John Machin <sjmachin@xxxxxxxxxxx>
- Date: Sun, 30 Apr 2006 23:02:41 +1000
On 30/04/2006 11:57 AM, kyo guan wrote:
Hi :
python list object like a stl vector, if insert a object in the front or the middle of it,
all the object after the insert point need to move backward.
look at this code ( in python 2.4.3)
for (i = n; --i >= where; ) /// here, why not use memmove? it would be more speed then this loop.
items[i+1] = items[i];
Here's a guess, based on similar work on another language a few reincarnations ago :-)
memmove() is very general-purpose, and starts with byte addresses and a byte count. For a small number of list elements, by the time that memmove has determined (1) the move overlaps (2) both source and target are on word boundaries and it is moving a whole number of words (3) what direction (up or down), the DIY code has already finished. For a large number of items, memmove *may* be faster (depending on the architecture and the compiler) but you are using the wrong data structure anyway.
.
- References:
- how not use memmove when insert a object in the list
- From: kyo guan
- how not use memmove when insert a object in the list
- Prev by Date: Re: resume picking items from a previous list
- Next by Date: Re: stdin: processing characters
- Previous by thread: how not use memmove when insert a object in the list
- Next by thread: Re: how not use memmove when insert a object in the list
- Index(es):