Thursday, January 21, 2021

Digest for comp.lang.c++@googlegroups.com - 2 updates in 2 topics

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jan 21 03:17PM -0800

Thanks to Bonita, I learned that C++17 actually works with alignas wrt
using new. This is very nice and am looking forward to using it quite a
bit. Here is some crude sample code:
 
can you compile it, and what is your output? Do you get any Crap? ;^)
_________________________
#include <iostream>
#include <atomic>
#include <cstdint>
#include <cstdlib>
 
 
static constexpr std::size_t ct_page_size = 8192;
static constexpr std::size_t ct_l2_cacheline_size = 64;
 
 
struct alignas(ct_l2_cacheline_size) ct_cacheline
{
std::atomic<std::uint64_t> m_state;
};
 
 
struct alignas(ct_page_size) ct_page
{
ct_cacheline m_line_0;
ct_cacheline m_line_1;
};
 
 
int main()
{
if (sizeof(ct_cacheline) != ct_l2_cacheline_size)
{
std::cout << "Crap! ct_cacheline is not padded!\n";
}
 
if (sizeof(ct_page) != ct_page_size)
{
std::cout << "Crap! ct_page is not padded!\n";
}
 
ct_page* page = new ct_page;
 
std::cout << "page = " << page << "\n";
 
if ((std::uintptr_t)(page) % ct_page_size)
{
std::cout << "Crap! page is not aligned!\n";
}
 
if ((std::uintptr_t)(&page->m_line_1) % ct_l2_cacheline_size)
{
std::cout << "Crap! page->m_line_1 is not aligned!\n";
}
 
delete page;
 
return 0;
}
_________________________
 
 
Now it seems as if alignas, at least on MSVC has a "limit". For instance
I am getting a compile time error using a ct_page_size of 8192 * 4.
 
_________________________
Error C2345 align(32768): illegal alignment value
 
Well, I am wondering why this would be a limitation?
_________________________
 
 
Thanks.
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jan 21 02:25PM -0800

On 1/21/2021 2:23 PM, Chris M. Thomasson wrote:
 
> I installed MSVC 2019, and your code still does not work. I am getting:
 
> doesn't fit
 
> What am I doing wrong here?
 
DOH! I was not compiling in C++17 mode. So, now it works. Cool.
 
Thanks.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: