milleniumbug / libzeeblasblas

experiment: what if we could create a standard library replacement (and try to avoid mistakes this time) for C++ from scratch?
MIT License
1 stars 0 forks source link

memory Allocation #3

Open ratchetfreak opened 7 years ago

ratchetfreak commented 7 years ago

The malloc - free api is horrible for what it does.

  1. there is no way for the allocator to store and get extra data about he memory block efficiently except by prefix. This adds holes that mess with any alignment you want to do.

  2. the allocator will likely over-allocate but user code can't use that fact unless they know the implementation details of the allocator.

So my idea is to separate a storage pointer from a usage pointer. The storage pointer has some extra data that the allocator's free or realloc can use.

Normal user code shouldn't have to worry about that and will will be able to use user pointers T* as normal and keep the storage pointers hidden in smart pointers and collections.

milleniumbug commented 7 years ago

Remodelling the memory allocation is also what I'd like to do. The first thing I want to do is to make passing the alignment mandatory (see std::allocator<T> being garbage and using operator new which makes it unusable with SSE types even though it has all the info it needs to allocate with correct alignment)

ratchetfreak commented 7 years ago

in C++17 operator new will have a version with an std::align_val_t param for types requiring alignments greater than the default.

Though operator new is kinda garbage anyway. User code shouldn't be using it and the only container that can actually use it is unique_ptr or shared_ptr or for the internal private structures which should probably be using unique_ptr or shared_ptr (or a thread-unsafe version) anyway.