constexpr auto path = "/mnt/pmem1/test/align";
constexpr auto LAYOUT = "AlignTest";
int main() {
alignas(64) int a[4];
alignas(64) int b[4];
struct alignas(64) C {
┆ alignas (64) p<std::array<int, 4>> c1;
┆ alignas (64) p<std::array<int, 4>> c2;
};
struct root {
┆ persistent_ptr<C> c;
};
pool<root> pop;
if (access(path, F_OK) != 0) {
┆ pop = pool<root>::create(path, LAYOUT);
┆ transaction::run(pop, [&] { pop.root()->c = make_persistent<C>(); });
} else {
┆ std::experimental::filesystem::remove_all(path);
┆ pop = pool<root>::create(path, LAYOUT);
┆ transaction::run(pop, [&] {
┆ ┆ delete_persistent<C>(pop.root()->c);
┆ ┆ pop.root()->c = make_persistent<C>();
┆ });
}
auto q = pop.root();
printf("a at %p\n", a);
printf("b at %p\n", b);
printf("q at %p\n", &*q);
printf("c at %p\n", &*q->c);
printf("c1 at %p\n", &q->c->c1.get_ro());
printf("c2 at %p\n", &q->c->c2.get_ro());
}a at 0x7ffd37d06780
b at 0x7ffd37d067c0
q at 0x7f3b63bc0550
c at 0x7f3b63c014d0
c1 at 0x7f3b63c014d0
c2 at 0x7f3b63c01510
struct C {
┆ alignas(64) p<std::array<int, 4>> c1;
┆ alignas(64) p<std::array<int, 4>> c2;
};0x7ffff4a014c0: 0x000000c0 0x00000000 0x79550b68 0xe55edbb3
0x7ffff4a014d0: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
0x7ffff4a014e0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a014f0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01500: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01510: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
0x7ffff4a01520: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01530: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01540: 0x00000000 0x00000000 0x00000000 0x00000000struct C {
┆ p<std::array<uint64_t, 6>> padding;
┆ p<std::array<int, 4>> c1;
┆ p<std::array<int, 4>> c2;
};0x7ffff4a014c0: 0x000000c0 0x00000000 0x79550b68 0xe55edbb3
0x7ffff4a014d0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a014e0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a014f0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01500: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
0x7ffff4a01510: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01520: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01530: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01540: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
0x7ffff4a01550: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01560: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01570: 0x00000000 0x00000000 0x00000000 0x00000000Thanks Piotr!
For completion with the following snippet, the previous desired alignment is achieved:struct C {
┆ alignas(64) p<std::array<int, 4>> c1;
┆ alignas(64) p<std::array<int, 4>> c2;
};
[...]
auto C_alloc = pop.ctl_set<struct pobj_alloc_class_desc>(
┆ ┆ "heap.alloc_class.new.desc", {64, 64, 2, POBJ_HEADER_COMPACT, 0});
transaction::run(pop, [&] {
┆ ┆ pop.root()->c = make_persistent<C>(allocation_flag::class_id(C_alloc.class_id));
});
The dump:0x7ffff4a01640: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01650: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01660: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a01670: 0x000000c0 0x00000000 0x79550b68 0xe55edbb3
0x7ffff4a01680: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
0x7ffff4a01690: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a016a0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a016b0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a016c0: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
0x7ffff4a016d0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a016e0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff4a016f0: 0x00000000 0x00000000 0x00000000 0x00000000
--Philipp
--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pmem+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pmem/c2b5fe48-d3fc-4835-8fb7-ac1db71982c5%40googlegroups.com.