Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Shared Memory Compilation Issue
From: TONGARI (tongari95_at_[hidden])
Date: 2011-07-27 13:22:09


2011/7/28 Nathan Lewis <nathanlewissubscription_at_[hidden]>

> TONGARI <tongari95 <at> gmail.com> writes:
>
>
> >
> > Define yourcomplex_data& operator=(complex_data const& other) I have no
> idea
> why compiler cannot generate this assignment operator which accepts const&,
> maybe it's because of the move emulation used by interprocess containers?
> >
>
> I am wondering if it is because there was internal vectors.

Not really.

> So I defined one and tested it in both applications using the shared memory
> and it seems to work. I defined it as below. Not sure if I really needed to
> loop over the vector in
> (rhs) or not was there a cleaner way to do this?

Normal assignment operator just works.

And if you want to push_back a elem into the vector, vector::emplace IMO is
the better way to go, and this doesn't require the operator=.

e.g.
    myComplexDataVector->emplace(myComplexDataVector->end(), 7, "hi", 7.0,
alloc_inst);

[...]

Also I am now focusing on destructing the object I take out of the vector in
> the
> application where I want to read what is put in. I realize that care must
> be
> taken when adding/deleting from the vector in two sample applications and
> think
> I know what I need to do for that. Also know that deleting from vectors
> isn't
> the most efficient way. But as far as the syntax of deleting an object from
> the
> vector which both reside in shared memory.
>
> I don't believe that pop_back deletes the object that's popped so am
> looking to
> firm up for sure how I'd delete one. Looking at the vast examples in the
> interprocess documentation it appears that one uses segment.destroy for
> objects
> that were created in shared memory with segment.construct, such as my
> vector of
> complex_data objects; and that for allocations of objects such as in the
> boost
> example at the bottom that are created by allocating segment.allocate the
> object
> in shared memory one uses segment.deallocate(object) call.
>
> However for objects that I've inserted into my vector in the code below, do
> I
> also need to call this deallocate method. I've tried it and it doesn't
> crash. I
> am looking to get some affirmation on this approach as I don't want to be
> creating a memory leak in shared memory.

Generally, you should not deallocate what you didn't allocate by yourself.
It's the container's job to deallocate its elems, and it's your job to
destruct the container when you don't need it anymore, like:

    segment.destroy<ComplexDataVector>("ComplexDataVector");



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net