###Bug: wrong allocation size###
Bug: wrong allocation size
I added a few extra int
fields to the test
class to make it 20 bytes large, and then ran your program. This is the output I saw:
0 created at: 0x1f8dc20
1 created at: 0x1f8dc28
2 created at: 0x1f8dc30
3 created at: 0x1f8dc38
As you can see, each element is only 8 bytes apart instead of 20. In fact, when I filled in the int
fields with values, the program quickly died on an assertion failure because I was overwriting the next_free
fields of neighboring entries.
###Possible fix###
Possible fix
I changed this line:
using storage_t = std::aligned_storage<sizeof(T), alignof(T)>;
to this:
using storage_t = typename std::aligned_storage<sizeof(T), alignof(T)>::type;
and got the following better output (with 24 byte allocations):
0 created at: 0x20e8c20
1 created at: 0x20e8c38
2 created at: 0x20e8c50
3 created at: 0x20e8c68
I'm not a C++ expert. I just looked at the examples from here and here to figure out the above change.
###Bug: wrong allocation size###
I added a few extra int
fields to the test
class to make it 20 bytes large, and then ran your program. This is the output I saw:
0 created at: 0x1f8dc20
1 created at: 0x1f8dc28
2 created at: 0x1f8dc30
3 created at: 0x1f8dc38
As you can see, each element is only 8 bytes apart instead of 20. In fact, when I filled in the int
fields with values, the program quickly died on an assertion failure because I was overwriting the next_free
fields of neighboring entries.
###Possible fix###
I changed this line:
using storage_t = std::aligned_storage<sizeof(T), alignof(T)>;
to this:
using storage_t = typename std::aligned_storage<sizeof(T), alignof(T)>::type;
and got the following better output (with 24 byte allocations):
0 created at: 0x20e8c20
1 created at: 0x20e8c38
2 created at: 0x20e8c50
3 created at: 0x20e8c68
I'm not a C++ expert. I just looked at the examples from here and here to figure out the above change.
Bug: wrong allocation size
I added a few extra int
fields to the test
class to make it 20 bytes large, and then ran your program. This is the output I saw:
0 created at: 0x1f8dc20
1 created at: 0x1f8dc28
2 created at: 0x1f8dc30
3 created at: 0x1f8dc38
As you can see, each element is only 8 bytes apart instead of 20. In fact, when I filled in the int
fields with values, the program quickly died on an assertion failure because I was overwriting the next_free
fields of neighboring entries.
Possible fix
I changed this line:
using storage_t = std::aligned_storage<sizeof(T), alignof(T)>;
to this:
using storage_t = typename std::aligned_storage<sizeof(T), alignof(T)>::type;
and got the following better output (with 24 byte allocations):
0 created at: 0x20e8c20
1 created at: 0x20e8c38
2 created at: 0x20e8c50
3 created at: 0x20e8c68
I'm not a C++ expert. I just looked at the examples from here and here to figure out the above change.
###Bug: wrong allocation size###
I added a few extra int
fields to the test
class to make it 20 bytes large, and then ran your program. This is the output I saw:
0 created at: 0x1f8dc20
1 created at: 0x1f8dc28
2 created at: 0x1f8dc30
3 created at: 0x1f8dc38
As you can see, each element is only 8 bytes apart instead of 20. In fact, when I filled in the int
fields with values, the program quickly died on an assertion failure because I was overwriting the next_free
fields of neighboring entries.
###Possible fix###
I changed this line:
using storage_t = std::aligned_storage<sizeof(T), alignof(T)>;
to this:
using storage_t = typename std::aligned_storage<sizeof(T), alignof(T)>::type;
and got the following better output (with 24 byte allocations):
0 created at: 0x20e8c20
1 created at: 0x20e8c38
2 created at: 0x20e8c50
3 created at: 0x20e8c68
I'm not a C++ expert. I just looked at the examples from here and here to figure out the above change.