-
Notifications
You must be signed in to change notification settings - Fork 392
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
Add aco_mem_new macro #23
base: master
Are you sure you want to change the base?
Conversation
Two types of allocation were done in the code, the former is the allocation to predefined size and the latter callocation of single object. I added a new macro aco_mem_calloc to handle the second case. I used the calloc insted of malloc + memset for brevity. This commit "breaks" C++ support.
One workaround if you wanna stick with # define aco_mem_new(ptr, size) do { \
ptr = static_cast<decltype(ptr)>(malloc(size)); \
assertalloc_ptr(ptr); \
} while (0);
# define aco_mem_calloc(ptr, count) do { \
ptr = static_cast<decltype(ptr)>(calloc(count, sizeof(*ptr))); \
assertalloc_ptr(ptr); \
} while (0); instead of |
Thank you very much for this PR, @platipo :D I am very sorry to reply so late.
Yes, but I'm afraid that I only agree with you partly. In the Code Style of linux kernel there is:
Which is also the convention been used in the libaco. In this case, the
I very appreciate your idea. For many situations, "calloc" is indeed usually more efficient than "malloc + memset".
I don't think the
And finally, please forgive me that I would like to deal with this PR after the commit of issue #22 since it has the highest priority ;-) |
I think that's the best thing to do. Seeing lowercase macros annoys me because I have always seen capitalized macro names even in function like macros and whats really bothers me is macro expansion.
If so why casting void pointers, it's not correct in C because they are automatically and safely promoted to any other pointer type.
Of course 😃 |
I followed your coding convention, but I think that lowercase macros are evil because it confuses newcomers, uppercase macros are convention.
I took the freedom to add a new macro
aco_mem_calloc
which you can read more details in the commit.Also I want to point out that this commit "breaks" C++ support, which was already broken by
_Static_assert
, because usingmalloc
in C++ is a really bad habit and there is no support fortypeof
of something similar in C++.Issue #3.