Boost logo

Boost :

Subject: Re: [boost] [ptr_container] ptr_vector across DLL boundaries
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-06-27 04:22:03


Robert Dailey skrev:
> On Fri, Jun 26, 2009 at 6:42 PM, Thorsten Ottosen <
> thorsten.ottosen_at_[hidden]> wrote:

>> Let me know if this allows you to solve your problem.
>
>
> Thanks Thorsten,
>
> I'm not familiar with how to use clone allocators in ptr_container yet, so
> I'll have to read through the documentation first to make sure I know how to
> use them. Given that, at what point will I need to be calling
> get_clone_allocator()? I figured I would just give ptr_vector my clone
> allocator and never need it back from the container. I expect my clone
> allocator to call the appropriate allocation method in its implementation
> details, which as I showed in an earlier example, will be a function located
> in the DLL itself.

In another thread you said:

> class clone_allocator
> {
> public:
> clone_allocator()
> {
> dll_clone_object = GetProcAddress();
> }
> MyClass* operator() ( MyClass const& node )
> {
> return dll_clone_object( node )
> }
>
> private:
> MyClass* (*dll_clone_object)( MyClass const& );
> };
>
> Note that the above is pseudocode. The point is, it would allow me to
> abstract the DLL factory function for creating clones, thus giving me
full
> control over which 'delete' and 'new' method is called (In this case, it
> would be the one from the DLL's memory manager).

so simply create a class like above, but implement the two functions
described here:

http://www.boost.org/doc/libs/1_39_0/libs/ptr_container/doc/reference.html#the-clone-allocator-concept

but make sure your my_clone_allocator has

1. non-static methods

2. is default constrictible

3. is swappable

Then create a container (for example) like this:

ptr_vector<T,my_clone_allocator> my_container;
my_container.get_clone_allocator().set_allocate_new = ...;
my_container.get_clone_allocator().set_deallocate = ...;

or something.

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk