Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the point of having wmemcpy? [duplicate]

Tags:

c

memory

This question applies both to C and C++.

memcpy basically copies raw memory from an address to another address. So my question is: what's the point of wmemcpy?

I mean, it's still contiguous space, and copying it is still the same process. It shouldn't matter if it's made of up wchar_t's, or should it?

like image 841
DeiDei Avatar asked Apr 30 '16 19:04

DeiDei


2 Answers

From MSDN documentation of wmemcpy:

memcpy copies count bytes from src to dest; wmemcpy copies count wide characters (two bytes).

So the difference is on how many bytes will be copied with the given same arguments,when you say:

memcpy(src,dest,2);//2 bytes will be copied
wmemcpy(src,dest,2);//4 bytes,i.e 2*2 bytes will be copied

Other than this difference and possible convenience of use when using wmemcpy when copying wchar_t arrays, i don't think there is a difference between the two and the existence of wmemcpy is really necessary.

like image 146
Biruk Abebe Avatar answered Sep 28 '22 03:09

Biruk Abebe


Interfac will ensure you copied whole wchar_t number of symbols. You won't be able to copy odd number of bytes

like image 31
Severin Pappadeux Avatar answered Sep 28 '22 02:09

Severin Pappadeux