Git Product home page Git Product logo

Comments (4)

foonathan avatar foonathan commented on September 25, 2024 1

I've changed memory_pool_collection to use the current block size instead, which should also solve the problem.

from memory.

cohdan avatar cohdan commented on September 25, 2024

It seems like the fixed block allocator does not work with memory pool collection - when I changed it to the growing block allocator all seems to work fine. I'd think that there shouldn't be a reason for the fixed allocator not to work in this case, am I wrong?
Anyway, I continue to look into this because I do need a fixed allocator and I do need several node sizes. Will be happy if anyone can still help.
Thanks.

from memory.

cohdan avatar cohdan commented on September 25, 2024

so the issue is that the memory pool collection always looks at the next block size when assigning memory to a bucket (free list) which will not work with fixed buffer as fixed buffer allocates the block in the creation of the object and then next block will always be 0.

@foonathan is this an intended behavior or a bug?
Thanks.

from memory.

cohdan avatar cohdan commented on September 25, 2024

In the meantime I wrote a wrppar class to the fixed allocator that returns the allocated block_size in next_block_size (instead of zero) and it seems to work fine.

template<class RawAllocator = memory::default_allocator>
    class fixed_block_allocator_for_memory_pool_collection {

    public:
        using allocator_type = memory::traits_detail::allocator_type<RawAllocator>;
        explicit fixed_block_allocator_for_memory_pool_collection(std::size_t block_size) noexcept
                                                                  : _underline_allocator(block_size, allocator_type()), _block_size(block_size) {}

        memory::memory_block allocate_block() {
            return _underline_allocator.allocate_block();
        }

        void deallocate_block(memory::memory_block block) noexcept {
            _underline_allocator.deallocate_block(block);
        }
        
        allocator_type& get_allocator() noexcept
        {
            return _underline_allocator.get_allocator();
        }

        std::size_t next_block_size() const noexcept {
            return _block_size;
        }

    private:
        size_t                                          _block_size;
        memory::fixed_block_allocator<RawAllocator>     _underline_allocator;
    };

Please let me know if this is something that you would like me to upload as a PR.

from memory.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.