On 10/17/2016 09:06 PM, Dr. David Alan Gilbert wrote: >> OK, memory was allocated at #2 >> > It is a bit confusing though (for a novice like me) that we have a non >> > ALLOC VBUFFER >> > whose pointer is NULL after post_load. > I don't think this pointer can be NULL; the sbreserve at #2 causes it to be > allocated. > But yes, it's a shame I can't use VMS_ALLOC here, but the sbreserve is not > a trivial allocation function.
Sorry my fault, wanted to say pre_load and not post_load. The assumption that backing memory is allocated either during device realization or in the pre_load of the parent or in vmstate_base_addr seemed a reasonable one (prior to the extra possibilities introduced by the patches of Jianjun). > >> > Now if I imagine the original stream were written in the following >> > sequence: >> > vbuffer_length (sb_datalen), vbuffer_data (sb_data), offsets (sb_wptr, >> > sb_rptr) >> > which seems completely valid to me then the context would not be sufficient >> > to compute sb_wptr and sb_rptr because the lifetime of vbuffer_data and >> > the tmp do not overlap. > If that was the case you could still do it pretty easily. > You'd have to add the sb_datalen and sb_data fields to the temporary > and then move the VMSTATE_VBUFFER_UINT32 into the tmp so it would operate > on the copied fields. > That basically means you expand the area affected by the tmp handling so that you have all the info you need to do the computation/transformation before the temporary is freed, right? Then the worst it can get is that you need to transform the first field and for that you need the last field. >> > I aware it's a trade-off between how long the temporary data lives and >> > how complicated the dependencies get. Or am I getting something wrong? > No, I think that's right. The other option I thought of was a macro > to allocate a temporary and then another to free it and then someway > to tell macros in between that they should operate on the temporary > rather than the main pointer; but then you'd have to be VERY careful > to not allow yourself to access a temporary that's been freed. > This structure means you can't make that mistake. > I have a couple of crazy half ideas of myself, I just do not feel very comfortable sharing them, because right now I do not have the capacity to explore them properly. Besides I don't know the code-base well enough to say if this reasoning has some practical relevance or is it 'rather academic'. Nevertheless I did not want to keep the opinion to myself that this thing with the dependencies can get rather convoluted under circumstances. Cheers, Halil > Dave > >> > >> > Cheers, >> > Halil >> > >>>> > >> + VMSTATE_END_OF_LIST() >>>> > >> + } >>>> > >> +}; >> > [..] >> >