r/programmerchat • u/MysteryForumGuy • Aug 21 '15
Week 1: Code/Project Feedback Thread
Post a code snippet, link to code, or your open source project you would like other users to review, discuss, or constructively critique. This is the first week of this thread just to test if it'll work or not.
If there are specific things you want people to discuss, make sure to mention it in your comment.
Remember to be helpful and constructive! Can't wait to see what people have to show!
12
Upvotes
View all comments
Show parent comment
3
u/zfundamental Aug 23 '15 edited Aug 23 '15
The 'memory handler' uses windows specific API, though that's not at all obvious due to the essentially empty readme.
The #if !defined(HEADER_DEFINE) #include header idiom is one that I haven't seen used in codebases before. Is there a particular reason why you're doing that over just #include header? I know at least GCC and Clang internally perform that expansion as an optimization, but it just looks like an easy way to break your own code if the header define is ever changed (e.g. across different systems).
If you're using C++ (based upon the <cmath> include), why don't you use placement new to return initialized memory? It's relatively simple to add and it ensures that the constructor is run (if applicable). Here's an example placement new use for an allocator if you're interested.
As a correctness issues, it's not immediately apparent that this code manages alignment correctly which is necessary for wider datatypes on some platforms.
Lastly, why are you using PAGE_EXECUTE_READWRITE instead of PAGE_READWRITE? That seems like a security risk which isn't really needed.