Note that there are some explanatory texts on larger screens.

plurals
  1. POstd::tuple memory alignment
    primarykey
    data
    text
    <p>Is there any formal specification for the layout and memory alignment for the pseudo members of a tuple?</p> <p>Is there anyway to modify the memory alignment of types in a tuple? Is it effected by a #pragma pack() directive?</p> <p>For example:</p> <pre><code>typedef std::tuple&lt;uint8_t, uint32_t&gt; myTuple; </code></pre> <p>Is there any specification that says this will be in memory the same as:</p> <pre><code>#pragma pack() // Default packing struct myStruct { uint8_t first; uint32_t second; } </code></pre> <p>Apologies if this is a stupid question but I don't entirely understand alignment when it comes to templates.</p> <p><strong>Edit: Example of what I'm trying to accomplish</strong></p> <p>Currently I have something along the lines of...</p> <pre><code>#pragma pack(push) #pragma pack(4) struct cTriangle { uint32 Index[3]; }; #pragma pack(pop) template &lt;class T&gt; inline bool Read(cFileStream&amp; fStream, std::vector&lt;T&gt;&amp; vec) { if (!vec.size()) return true; // fStream.Read(void* pBuffer, size_t Size) // Just a wrapper around a binary ifstream really return fStream.Read(&amp;vec[0], sizeof(T) * vec.size()); } std::vector&lt;cVector3&gt; vPoint; vPoint.resize(Verticies); bool result = Read(FileStream, vPoint); </code></pre> <p>If I wanted to typedef <code>cTriangle</code> as <code>std::tuple&lt;uint32, uint32, uint32&gt;</code> for metaprogramming purposes would I still be able to read/write to the raw memory of the tuple (and thus a vector of tuples) or would that memory have unknown alignment?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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