kzalloc()_kcalloc()

定义在/include/linux/slab.h中

1. kzalloc()
--- kmalloc + memset 0;

    /**
     * kzalloc - allocate memory. The memory is set to zero.
     * @size: how many bytes of memory are required.
     * @flags: the type of memory to allocate (see kmalloc).
     */
    static inline void *kzalloc(size_t size, gfp_t flags)
    {
        return kmalloc(size, flags | __GFP_ZERO);
    }

2. kcalloc() --- 分配n块内存,kmalloc + memset 0
    /**
     * kcalloc - allocate memory for an array. The memory is set to zero.
     * @n: number of elements.
     * @size: element size.
     * @flags: the type of memory to allocate.
     *
     * The @flags argument may be one of:
     *
     * %GFP_USER - Allocate memory on behalf of user. May sleep.
     *
     * %GFP_KERNEL - Allocate normal kernel ram. May sleep.
     *
     * %GFP_ATOMIC - Allocation will not sleep. May use emergency pools.
     * For example, use this inside interrupt handlers.
     *
     * %GFP_HIGHUSER - Allocate pages from high memory.
     *
     * %GFP_NOIO - Do not do any I/O at all while trying to get memory.
     *
     * %GFP_NOFS - Do not make any fs calls while trying to get memory.
     *
     * %GFP_NOWAIT - Allocation will not sleep.
     *
     * %GFP_THISNODE - Allocate node-local memory only.
     *
     * %GFP_DMA - Allocation suitable for DMA.
     * Should only be used for kmalloc() caches. Otherwise, use a
     * slab created with SLAB_DMA.
     *
     * Also it is possible to set different flags by OR'ing
     * in one or more of the following additional @flags:
     *
     * %__GFP_COLD - Request cache-cold pages instead of
     * trying to return cache-warm pages.
     *
     * %__GFP_HIGH - This allocation has high priority and may use emergency pools.
     *
     * %__GFP_NOFAIL - Indicate that this allocation is in no way allowed to fail
     * (think twice before using).
     *
     * %__GFP_NORETRY - If memory is not immediately available,
     * then give up at once.
     *
     * %__GFP_NOWARN - If allocation fails, don't issue any warnings.
     *
     * %__GFP_REPEAT - If allocation fails initially, try once more before failing.
     *
     * There are other flags available as well, but these are not intended
     * for general use, and so are not documented here. For a full list of
     * potential flags, always refer to linux/gfp.h.
     */
    static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
    {
        if (size != 0 && n > ULONG_MAX / size)
            return NULL;
        return __kmalloc(n * size, flags | __GFP_ZERO);
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值