J'ai installé boost::interprocess. J'arrive à compiler les exemples, tout va bien
J'ai lu une bonne partie de la documentation. La section STL compatible allocators est assez intéressantes. J'ai vu que cette librairie redéfinissait tous les conteneurs standards. Je pense qu'il faut que je me base sur boost::interprocess::allocator qui ressemble très fort à std::allocator (je me suis permis de copier-coller la doc à la fin du post). La seule différence c'est l'utilisation de :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
/*!Returns the segment manager. Never throws*/
   segment_manager* get_segment_manager() const;
pour les allocations mémoire. J'ai également lu la section consacre à ces segment_manager, mais je ne comprends pas comment allouer de grosse quantité de mémoire en les utilisant. J'ai besoin de votre aide pour quelques explications. Notamment, s'il faut modifier les classes...

Merci!


boost::interprocess::allocator: STL compatible allocator for managed memory segments
The boost::interprocess::allocator class defines a STL compatible allocator class that uses the managed memory segment's algorithm to allocate and deallocate memory. This is achieved though the segment manager of the managed memory segment. This allocator is templatized with the allocated type, and the segment manager.

To use boost::interprocess::allocator, you must include the following header:


Code : Sélectionner tout - Visualiser dans une fenêtre à part
#include <boost/interprocess/allocators/allocator.hpp>

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
namespace boost::interprocess {
 
/*!An STL compatible allocator that uses a segment manager as 
   memory source. The internal pointer type will of the same type (raw, smart) as
   "typename SegmentManager::void_pointer" type. This allows
   placing the allocator in shared memory, memory mapped-files, etc...*/
template<class T, class SegmentManager>
class allocator 
{
   public:
 
   /*!Returns the segment manager. Never throws*/
   segment_manager* get_segment_manager() const;
 
   /*!Constructor from the segment manager. Never throws*/
   allocator(segment_manager *segment_mngr);
 
   //The rest of the interface is the same of std::allocator
};
 
}} //      namespace boost::interprocess {
The class allocator must be always initialized with the allocation algorithm obtained from the segment where you want boost::interprocess::allocator to allocate memory.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
//Alias allocator type with
//    T=int
//    SegmentManager = managed_shared_memory::segment_manager
typedef allocator<int, managed_shared_memory::segment_manager> Allocator;
 
//Initialize allocator with the segment manager
Allocator alloc_inst (segment.get_segment_manager());
The allocator just provides the needed typedefs and forwards all allocation and deallocation requests to the segment manager passed in the constructor.