Share via


memmove、wmemmove

更新 : 2007 年 11 月

バッファの内容をほかのバッファに移動します。これらの関数のセキュリティを強化したバージョンについては、「memmove_s、wmemmove_s」を参照してください。

void *memmove(
   void *dest,
   const void *src,
   size_t count 
);
wchar_t *wmemmove(
   wchar_t *dest,
   const wchar_t *src,
   size_t count
);

パラメータ

  • dest
    コピー先のオブジェクト。

  • src
    コピー元のオブジェクト。

  • count
    コピーするバイト数 (memmove) または文字数 (wmemmove)。

戻り値

dest の値を返します。

解説

count バイト数 (memmove) または文字数 (wmemmove) を src から dest にコピーします。コピー元とコピー先の領域の一部が重なり合っている場合、両方の関数は、重なり合っている領域のコピー元のバイトをコピーした後で上書きします。

セキュリティに関するメモ   コピー先のバッファのサイズがコピー元のバッファのサイズ以上であることを確認してください。詳細については、「Avoiding Buffer Overruns」を参照してください。

次の例のように、memmove 関数および wmemmove 関数が使用されなくなるように _CRT_SECURE_DEPRECATE_MEMORY 定数をインクルード ステートメントの前で定義すると、これらの関数だけが使用されなくなります。

#define _CRT_SECURE_DEPRECATE_MEMORY
#include <string.h>
or
#define _CRT_SECURE_DEPRECATE_MEMORY
#include <wchar.h>

必要条件

ルーチン

必須ヘッダー

memmove

<string.h>

wmemmove

<wchar.h>

互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。

使用例

// crt_memcpy.c
// Illustrate overlapping copy: memmove
// always handles it correctly; memcpy may handle
// it correctly.
//

#include <memory.h>
#include <string.h>
#include <stdio.h>

char str1[7] = "aabbcc";

int main( void )
{
   printf( "The string: %s\n", str1 );
   memcpy( str1 + 2, str1, 4 );
   printf( "New string: %s\n", str1 );

   strcpy_s( str1, sizeof(str1), "aabbcc" );   // reset string

   printf( "The string: %s\n", str1 );
   memmove( str1 + 2, str1, 4 );
   printf( "New string: %s\n", str1 );
}

The string: aabbcc
New string: aaaabb
The string: aabbcc
New string: aaaabb

.NET Framework の相当するアイテム

System::Buffer::BlockCopy

参照

参照

バッファ操作

_memccpy

memcpy、wmemcpy

strcpy、wcscpy、_mbscpy

strncpy、_strncpy_l、wcsncpy、_wcsncpy_l、_mbsncpy、_mbsncpy_l