𝗝𝗮𝗺𝗲𝘀
Does structs generate inaccessible copies?
Consider the following large structure for the asked questions
Does a local copy is created when returning from a method?
In my understanding of how structure returning methods are handled, the current method will allocate the necessary memory to store the called method's return within the stack. But, the called method also has it's own stack, so, in the next scenarios, does the struct gets copied back in forth or is it internally passed by reference?
When
Main
invokes CreateMe
is the structure allocated inside the creator method or does the compiler detects that no one can access it so it makes new()
allocate directly into x
's var memory?
What if the variable is accessed in the creator method but only returned
Since the value temp
is only modified and then returned, is the memory for it allocated in CreateMe
's stack and then copied to the caller method stack or accessed directly?
Does a a copy of a struct is created when passing through an init accessor?
When creating a Data
instance, the IL method init_Payload
is called. So the stack traces looks something like the following .With that in mind, does the large structure gets copied 2 times or the compiler optmises that in some way?
Main() -> CreateMe() -> init_Payload
new Data() | => new(); | arg: value12 replies
Are streams any better than byte array outside of I.O context?
Streams are visibly better when working with files, network responses and many other cases, but, when specifically working with objects which already live within RAM memory, are streams still useful? I.E why does Binary Formatter used streams when formatting managed objects?
The understanding that I have from streams is a lot like IEnumerable<byte> with a temp buffer, meaning, nothing happens upon creation until fetched.
Maybe postpone an action till last moment?
6 replies