Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>what make me confuse is, why you need to allocate or create an object in SharedMemory (SHM), for example if you reserve shared memory of the size 65536 Bytes, then suppose you get your shared memory at address <code>0x1ABC0000</code>, if reservation success you will have free and directly accessible memory space at <code>0x1ABC0000 to 0x1ABCFFFF</code>.</p> <p>then when your application need to "allocate" object in SHM of size <code>sizeof(SHMObject)</code>, and your memory manager see that address at <code>0x1ABC0000+0x1A</code> is free, your memory manager should just return <code>0x1ABC001A</code> value, and mark <code>( 0x1ABC001A to 0x1ABC001A+sizeof(SHMObject) )</code> was occupied, and you just need to cast: <code>SHMObject* shmObjectPtr = (SHMObject*)(0x1ABC001A);</code></p> <p>and ofcourse that is assuming you have your own custom memory allocator that work on specified range of memory address.</p> <p>as for template, i don't really understand how does your SHM ring buffer look like, but I've done that before using SHM, my implementation is like this: `</p> <pre><code>//memory SHM allocator template&lt;typename T&gt; class ShmRingAllocator { protected: void* baseAddress; public: ShmRingAllocator(void* baseAddress,int memSize); void* allocate(); //this function do what I described earlier, or you can use placement new: new (baseAddress+offset)T; } //some kind of shared_ptr&lt;&gt; that handle object in SHM, this provides mechanishm to check is the pointer still valid in shm or not template&lt;typname T&gt; ShmRingObjectPtr { protected: T* object; //mapped address of object at current process ShmBuffer* shm; //every object has pointer to which SHM does this pointer pointing at public: virtual T* operator-&gt;(); //operator overload to access T object } class ShmBuffer //base class for all kind of SHM buffer { protected: std::string shmName; void* shmBasePtr; } template&lt;typename T,class A=ShmRingAllocator&lt;T&gt;&gt; ShmRingBuffer : public ShmBuffer { protected: A allocator; public: ShmRingObjectPtr&lt;T&gt; insert() //push one element to ring buffer { return ShmRingObjectPtr&lt;T&gt;((T*)this-&gt;allocator.allocate(),this); } } </code></pre> <p>`</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload