在三星研发分班测试中出现了一个问题:calloc 分配的最大大小是多少?a)16k b)32k c)64k d)128k
我不知道正确的答案。谁能告诉我正确的答案。
这是一个无意义的问题,因为它高度依赖于系统。没有一个答案是正确的;在某些系统中,您可以使用calloc()
兆字节和千兆字节的内存。
Theoratically the maximum is the value one could request. For
void *calloc(size_t nmemb, size_t size);
that is:
nmemb * size
SIZE_MAX * SIZE_MAX
With SIZE_MAX
being the limit of size_t
.
However as size_t
is the result of the sizeof
operator the theoratical maximum is limited to SIZE_MAX
.
它与您的编译器和您的机器架构有关,例如:
int = 2 byte in some machine
int = 4 bye in some machine