Boost logo

Boost :

Subject: [boost] [pool] Definition of a static_pool ?
From: DUPUIS Etienne (e.dupuis_at_[hidden])
Date: 2012-04-24 06:35:52


The Boost.Pool class describes a pool of buffer, pool whose size grows as needed.

This is very convenient but there usage cases where the pool should not perform any dynamic memory allocation, i.e. the maximum number of simultaneously required buffers is known at initialization. I have hence defined a simple class 'static_pool' (see below), which
(i) allocate all requested buffers at initialization;
(ii) fails (returns null) if more buffers are being asked for at runtime.

Does such a class has its place within the Boost Pool library ?



#include <boost/pool/pool.hpp>

namespace boost

template<typename UserAllocator>
class static_pool : protected pool<UserAllocator> {
    public : // Overridden functions
        explicit static_pool(const size_type nrequested_size) : pool<UserAllocator>(nrequested_size, nrequested_size)
            { free(malloc()); }

        void * malloc()
            { return store().empty() ? NULL : store().malloc(); }

    public : // Inherited functions
        void free(void * const chunk)
            { return pool<UserAllocator>::free(chunk); }

        size_type get_requested_size() const
            { return pool<UserAllocator>::get_requestedSize(); }

        bool is_from(void * const chunk) const
            { return pool<UserAllocator>::is_from(chunk); } };



Ce message et toutes les pièces jointes sont confidentiels et établis à l'intention exclusive de ses destinataires. Toute modification, édition, utilisation ou diffusion non autorisée est interdite. Si vous avez reçu ce message par erreur, merci de nous en avertir immédiatement. ATEME décline toute responsabilité au titre de ce message s'il a été altéré, déformé, falsifié ou encore édité ou diffusé sans autorisation.
This message and any attachments are confidential and intended solely for the addressees. Any unauthorized modification, edition, use or dissemination is prohibited. If you have received this message by mistake, please notify us immediately. ATEME decline all responsibility for this message if it has been altered, deformed, falsified or even edited or disseminated without authorization.

Note: To protect against computer viruses, e-mail programs may prevent sending or receiving certain types of file attachments.

Boost list run by bdawes at, gregod at, cpdaniel at, john at