c++ - Retrieving shared vectors from Boost InterProcess Shared Memory -
i have created boost shared memory, purpose of sharing vectors.
the sharing has been accomplished.
however, not understand how vectors pushed shared memory.
i push_back
shared memory writing process. vectors being pushed stack push
shared memory, in lifo order?
the other application, reader, retrieves vector in following fashion :
managed_shared_nmemory segment (open_only, "shared_mem_name"); vector = segment.find<vector_type>("vector_name").first; if (vector != null) { //codde }
now here, vector reading. 1 pushed in last ( newest 1 )? , if i'm reading it, imply vector popped? i.e. still there in shared memory after read, , if so, shared memory overflow after time, , how stop it? don't see in documentation regarding it...
the vectors aren't "pushed" shared memory. there no implicit stack.
instead, vector lives in shared memory. you're reading in fact same vector in process, at same time.
note implies need shared mutex synchronize access too, otherwise you'll have data races between threads (from different processes) , definition undefined behaviour in c++.
on different angle:
i
push_back
shared memory writing process. vectors being pushed stack push shared memory, in lifo order?
breaking down:
i
push_back
shared memoryno don't.
push
vector elementback
of 1 vector. vector single thing shared, under name"vector_name"
so vectors being pushed
no, vectors stay are: in shared memory.
like stack push shared memory, in lifo order?
no, there's 1 vector. vector ordered sequential container. supports random access, so
for (auto = v.begin(); it!= v.end(); ++it) { // process `*it` in order }
vs
for (auto = v.rbegin(); it!= v.rend(); ++it) { // process `*it` in reversed order }
if use
push_back
insert,in order
iteration "fifo"
Comments
Post a Comment