Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ vector How to change internal pointer
    primarykey
    data
    text
    <p>I would like to serialize vector. And I dunno how to change pointer of vector.. To make it simple, let's say I have a vector something like:</p> <pre><code>vector&lt;char&gt; v; </code></pre> <p>And I have this pointer:</p> <pre><code>char* c = { 'v', 'e', 'c', 't', 'o', 'r' }; </code></pre> <p>And I would like my vector v's internal pointer points my char* c:</p> <pre><code>&amp;v[0] -&gt; c </code></pre> <p>How can I adjust vector that it would point c? Is there any way to do it? </p> <hr> <p><strong>EDIT 22.10.2010</strong></p> <p>So guys, after debugging vector I came up with this solution:</p> <pre><code>vector&lt;char&gt; dump; memcpy(&amp;myVector, &amp;dump, sizeof(myVector)); // I change contents so it can work myVector.assign(buf, buf+5); // copy contents into it from buffer (I don't like this part) </code></pre> <p>And to work this I needed to define </p> <pre><code>_ITERATOR_DEBUG_LEVEL=0 </code></pre> <p>because it's initially set to 2 and it actually does a debug check (I guess) This is not defined in release mode also right? So it's my workaround for now, I would like to force ppl to remove vector in long term... So guys what are you thinking about this solution? And dangers you see?</p> <hr> <p>I actually need to serialize vector by memcpy. I want to serialize my whole class (like taking a snapshot of memory) and write it to a file, and when reloading read it from file and restore the object as without calling its constructor and using new operator.</p> <p>Umm this vector container is taking place on stack memory, so memcpy cannot reach it since it's only concern is heap... Well this piece of code might work for me for now:</p> <p>copy(buf, buf + 5 myVvector.begin());</p> <p>Well this is not working also, since I do not use new keyword on my class, this vector, as far as I understan, is not initialized. So if I try to copy, push_back_fill this vector with smt, it gives me this error: </p> <p>Unhandled exception at 0x00ec455b in newDel.exe: 0xC0000005: Access violation reading location 0x00654b4c.</p> <p>which makes sense... So anybody knows how can I call constructor/initializor of vector from outside?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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