mtrebi / memory-allocators

Custom memory allocators in C++ to improve the performance of dynamic memory allocation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make AllocationHeader::padding size_t

legends2k opened this issue · comments

Compilation Error

When compiling with Clang on Xcode, I get the following error

../src/StackAllocator.cpp:39:39: error: non-constant-expression cannot be narrowed from type 'std::size_t' (aka 'unsigned long') to 'char' in initializer list [-Wc++11-narrowing]
    AllocationHeader allocationHeader{padding};
                                      ^~~~~~~
../src/StackAllocator.cpp:39:39: note: insert an explicit cast to silence this issue
    AllocationHeader allocationHeader{padding};
                                      ^~~~~~~
                                      static_cast<char>( )

Compiler Details

Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

In case padding can go beyond 255, it makes sense to make AllocationHeader::padding a size_t instead of a char as suggested by @talhasaruhan in #8.