c++ - precision about structure loading in memory -


typedef struct sample_s  {   int sampleint;   sample2 b; } sample;  typedef struct sample2_s {   int a;   int b;   int c;   int d; } sample2;  int main() {   sample t; } 

in example, when create instance t of sample structure, load sample2 in memory.

the question is, how possible load sampleint in memory ? there way load part of structure in memory ? if answer is, think is, inheritance. how work ? there waste of time during execution due hash table ?

i asking question because want develop dod (data oriented design) program , want understand better how structures managed in memory.

thank you

if want copy sampleint, can declare int s = x.sampleint; can memcpy() range of memory defined offsetof macro in <stddef.h> range of consecutive member variables.

it seems if want 1 of following:

declare samplebase type that, in c++, sample can inherit from.

declare storage individual members want copy.

have sample hold pointer sample2, , set null if aren’t allocating one.

declare sample temporary in block of code, copy parts want, let memory reclaimed when goes out of scope.


Comments