C dilinde memcpy ve memmove farkı nedir?

Raptor

Kilopat
Katılım
29 Mayıs 2017
Mesajlar
162
Çözümler
2
Merhaba. Başlıkta gördüğünüz üzere memcpy ve memmove arasındaki fark nedir acaba? Küçük bir örnek ile anlatabilirseniz çok sevinirim.
 
memmove memcpy'den daha hızlı çalışır.
Bu içeriği görüntülemek için üçüncü taraf çerezlerini yerleştirmek için izninize ihtiyacımız olacak.
Daha detaylı bilgi için, çerezler sayfamıza bakınız.
 
Stackoverflow'da şöyle bir şey buldum:

Kod:
With memcpy, the destination cannot overlap the source at all.
With memmove it can.
This means that memmove might be very slightly slower than memcpy, as it cannot make the same assumptions.

For example, memcpy might always copy addresses from low to high.
If the destination overlaps after the source, this means some addresses will be overwritten before copied.
memmove would detect this and copy in the other direction - from high to low - in this case.
However, checking this and switching to another (possibly less efficient) algorithm takes time.
 
memmove memcpy'den daha hızlı çalışır.

Tam tersi şeklinde biliyorum.
memmove kopyalanan ve kopyalanacak alanları kontrol eder. Eğer örtüşme problemi yoksa memcpy'e dallanır ve memcpy çalışır. Yani memcpy'e göre fazladan kontrol görevleri vardır.
memcpy ise memmove'a göre kontrolsüz sayılabilecek bir şekilde olduğu gibi sıradan verileri kopyalar.
 

Geri
Yukarı