栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

NUMA感知的高速缓存对齐的内存分配

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

NUMA感知的高速缓存对齐的内存分配

如果您只是希望围绕NUMA分配器获得对齐功能,则可以轻松构建自己的对齐功能。

想法是将未对齐的

malloc()
空间称为更多空间。然后返回第一个对齐的地址。为了释放它,您需要将基址存储在已知位置。

这是一个例子。只需用适当的名称替换名称:

pint         //  An unsigned integer that is large enough to store a pointer.NUMA_malloc  //  The NUMA malloc functionNUMA_free    //  The NUMA free functionvoid* my_NUMA_malloc(size_t bytes,size_t align,  ){    //  The NUMA malloc function    void *ptr = numa_malloc(        (size_t)(bytes + align + sizeof(pint)),            );    if (ptr == NULL)        return NULL;    //  Get aligned return address    pint *ret = (pint*)((((pint)ptr + sizeof(pint)) & ~(pint)(align - 1)) + align);    //  Save the free pointer    ret[-1] = (pint)ptr;    return ret;}void my_NUMA_free(void *ptr){    if (ptr == NULL)        return;    //  Get the free pointer    ptr = (void*)(((pint*)ptr)[-1]);    //  The NUMA free function    numa_free(ptr); }

要使用此功能,您需要调用

my_NUMA_free
分配的任何内容
my_NUMA_malloc



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380278.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号