Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check object alignment at runtime. #60

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion hvcc/generators/ir2c/templates/Heavy_NAME.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,28 @@ extern "C" {
{%- endfor %}
{%- endif %}


#ifdef __EXCEPTIONS
class my_bad_alloc : public std::bad_alloc {
virtual const char* what() const noexcept
{
return "Heavy_{{name}} object is improperly aligned. Avoid heap allocation, use operator new or use -std=c++17\n";
}
};
#endif // __EXCEPTIONS

/*
* Class Functions
*/

Heavy_{{name}}::Heavy_{{name}}(double sampleRate, int poolKb, int inQueueKb, int outQueueKb)
: HeavyContext(sampleRate, poolKb, inQueueKb, outQueueKb) {
#ifdef __EXCEPTIONS
if(size_t(this) & size_t(alignof(Heavy_{{name}}) - 1))
{
my_bad_alloc e;
throw(e);
}
#endif // __EXCEPTIONS
{%- for x in init_list %}
numBytes += {{x}}
{%- endfor %}
Expand Down