struct alignas(64) CacheLineAligned {
    // 这里放置需要对齐的变量
    int a;
    double b;
    char c;
};

int main(int argc, const char *argv[]) {

    std::cout << "Cache line size: " << 64 << " bytes" << std::endl;

    CacheLineAligned obj;
    std::cout << "Object size: " << sizeof(obj) << " bytes" << std::endl;
    std::cout << "Object address: " << &obj << std::endl;

    return 0;
}

Logo

加入社区!打开量化的大门,首批课程上线啦!

更多推荐