简体   繁体   English

为数组分配内存和分配内存之间的区别

[英]Difference between allocating memory and allocating memory for an array

Is there a meaningful difference between kmalloc and kmalloc_array ? kmallockmalloc_array之间有有意义的区别吗?

I was under the impression that memory was memory, but as it is described here there appears to be some difference. 我的印象是,记忆是记忆,但因为它是描述这里似乎存在一定差异。

kmalloc — allocate memory kmalloc —分配内存

kmalloc_array — allocate memory for an array. kmalloc_array —为数组分配内存。

Are they just two different ways to accomplish the same thing? 他们只是完成同一件事的两种不同方式吗?

From the kernel-source (slab.h) 从内核源代码(slab.h)

/**
* kmalloc_array - allocate memory for an array.
* @n: number of elements.
* @size: element size.
* @flags: the type of memory to allocate (see kmalloc).
*/
static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
{
      if (size != 0 && n > SIZE_MAX / size)
             return NULL;
      return __kmalloc(n * size, flags);
}

I wonder who needed that ;)) 我想知道谁需要那个;))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM