-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Added user propagator example #5625
Conversation
@CEisenhofer note that it doesn't build. |
../examples/c++/userPropagator.cpp:47:27: warning: field 'cnt' will be initialized after field 'values' [-Wreorder-ctor] |
/usr/bin/ld: userPropagator.o: in function |
Strange, for me (GCC 11 - WSL Ubuntu) it compiles without problems. How do you build the example? |
You should look at the output of the hosted builds. Click on "Details" |
There are also many warnings, such as
These are easy to fix |
examples/c++/userPropagator.cpp
Outdated
unsigned cnt; | ||
|
||
model(unsigned cnt) : cnt(cnt), values(nullptr) { | ||
values = (unsigned*) malloc(sizeof(unsigned) * cnt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use malloc from c++?
examples/c++/userPropagator.cpp
Outdated
|
||
protected: | ||
|
||
std::unordered_map<unsigned, unsigned> *id_mapping; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want & instead of *. It saves a character on dereference (. instead of ->) and captures invariant of being non-null
examples/c++/userPropagator.cpp
Outdated
|
||
model* clone() const { | ||
model *newModel = new model(cnt); | ||
memcpy(newModel->values, values, sizeof(unsigned) * cnt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just have a constructor for model that performs clone.
examples/c++/userPropagator.cpp
Outdated
|
||
~user_propagator() { | ||
delete currentModel; | ||
currentModel = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setting to nullptr is redundant. C++ has scoped ptr that does the free automatically.
examples/c++/userPropagator.cpp
Outdated
for (unsigned i = 0; i < num_scopes; i++) { | ||
unsigned lastCnt = fixedCnt.top(); | ||
fixedCnt.pop(); | ||
for (unsigned j = (unsigned) fixedValues.size(); j > lastCnt; j--) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (auto j = fixedValues.size(); j > lastCnt; j--)
examples/c++/userPropagator.cpp
Outdated
#define Write(x) | ||
#endif | ||
|
||
class model { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why you need a model abstraction.
Why not class model : public std::vector {};
(+ removed unused parameter warning)
Thanks for your comments! I've refactored the code accordingly. However, I've no clue why the build tries to link the cpp_example.o and the userPropagator.o. (From Azure's log: |
No description provided.