简体   繁体   中英

How to instantiate C++ objects on specific NUMA memory nodes?

Simple C code can use libnuma library to allocate memory in specific memory node in a NUMA system. For example, it can be done using following function:

void *numa_alloc_onnode(size_t size, int node)

How one instantiate a class in some memory node? One way, I can think of is:

numa_set_membind(<nodemask>);
o = new Object();
numa_set_localalloc();

Will this work?

Placement new is what you are looking for. Example:

void *blob = numa_alloc_onnode(sizeof(Object), ...);
Object *object = new(blob) Object;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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