ValueType stack reference #63089
Unanswered
emceelovin
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Have you examined operations for references, e.g. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wrote an IL emitted POCO serializer, and anytime i can access a ValueType larger than the processor word size by address, for reading/writing, i have. Anything else, copying it is 100% completely ok. One of the optimizations i would like to make involves large ValueType's that end up on the stack indirectly as a result of calling property get accessors, emitting newobj, etc. As you all know, ValueType's on the stack can be used as function call arguments, but you can't directly use the ValueType on the stack itself emitting a call to say a property's get accessor method. To operate on the ValueType with object oriented semantics, you have to emit stloc, push it into a local, emit ldloc/ldloca, and then you can emit call to a property accessor. Unless i'm absolutely blind when it comes to IL instructions, but i've searched through them all. I'm sure there is a runtime reason for this, so that's why i'm asking this. It's just weird that, the ValueType has to be in a local before being accessed. Which you then can emit ldloc(which pushes the ValueType as a whole BACK onto the stack) or even lodoca, and operate on on the ValueType. Why can't there be an instruction, or is there, i can emit, while supplying a type token, that can essentially do ESP - sizeof(token) to arrive at the beginning of where the type lives at on the stack? Then, I would have it's address, while it's still on the stack. Which can be used for any instruction that takes a reference. Is this all due to RTTI not existing on the stack? Essentially just the raw data of a Type exists, but no type information, but once you store it into the Type housing, you can then access it's data? I tried a pretty cheap "hack" to get what i wanted to work, to work, but it only succeeded partially. Which leads me to believe this is possible maybe(?), but i just don't know how, or it's not, and somehow this ALMOST worked. With the Nullable that's pushed onto the stack from a property get accessor, I emitted a call to a static dummy function that took a T as its first parameter, with hope's that the Nullable.value, the last member, of a Nullable, would make it into the function. It did, but i only had two of the three fields with correct data. I assume due to type padding. This isn't all meant to be a rant. I'm just curious. Any criticism is helpful.
Beta Was this translation helpful? Give feedback.
All reactions