Comments (2)
Is this warning ok?
src/StackAllocator.cpp:42:46: warning: narrowing conversion of 'padding' from 'std::size_t {aka long unsigned int}' to 'char' inside { } [-Wnarrowing]
AllocationHeader allocationHeader{padding};
^
from memory-allocators.
Well, the author of the code defined AllocationHeader struct as follows (in the header file):
struct AllocationHeader {
char padding;
};
so when using list initialization, you're converting "padding" variable from size_t to char, which is theoretically not safe. BUT, since the actual padding will almost always fit into a char (meaning that it's integer value has to be less than 256) it'll work just fine. But if you're trying to align to huge blocks of memory, then padding may overflow.
So the best way to handle this depends on your use case, if you can assume that paddings before headers will always be less than or equal to 255, then you can just ignore the warning. But if you're trying to, for some reason align your blocks to huge chunks, say 512, then padding CAN overflow (or it may be undefined behavior, either case it's unsafe) so you should change the "char" in the definition to "size_t"
from memory-allocators.
Related Issues (20)
- Can you share rest ppt of Dynamic memory ? HOT 2
- FreeListAllocator :: FindBest() question HOT 1
- I made mistake, sorry
- Bug in Free List Allocator on 32bit systems HOT 3
- Build errors HOT 3
- How to use allocated memory HOT 3
- why use virtual method HOT 1
- find a small bug here HOT 2
- Make AllocationHeader::padding size_t
- StackAllocator is not performant and wastes memory on padding
- Optimize PoolAllocator initialization by adding an Offset variable?
- Found a bug in StackAllocator
- using malloc on custom memory allocator HOT 1
- Can't compile the code. HOT 4
- Question about FreeListAllocator HOT 2
- add simple example HOT 1
- Error while compiling in MSVC HOT 3
- consider adding tests HOT 1
- Potential infinite loop caused by linked list node pointing to itself HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from memory-allocators.