What is the maximum size of buffers memcpy/memset etc. can handle?

前端 未结 6 2086
执笔经年
执笔经年 2020-12-11 04:54

What is the maximum size of buffers memcpy and other functions can handle? Is this implementation dependent? Is this restricted by the size(size_t) passed in as an argument?

6条回答
  •  爱一瞬间的悲伤
    2020-12-11 05:18

    Functions normally use a size_t to pass a size as parameter. I say normally because fgets() uses an int parameter, which in my opinion is a flaw in the C standard.

    size_t is defined as a type which can contain the size (in bytes) of any object you could access. Generally it's a typedef of unsigned int or unsigned long.
    That's why the values returnes by the sizeof operator are of size_t type.

    So 2 ** (sizeof(size_t) * CHAR_BIT) gives you a maximum amount of memory that your program could handle, but it's certainly not the most precise one.
    (CHAR_BIT is defined in limits.h and yields the number of bits contained in a char).

提交回复
热议问题