c# - Should I re-use a Struct? -


i know structs value types , live on stack, unless declared field in reference type, , contain values in memory @ location. i'm wondering whether or not efficient or worthwhile re-use declared struct in iterated loop rather creating new 1 each time. how costly stack instantiate variables, if @ all? also, related question, if instantiate struct inside method call create local copy of struct or create first parameter of method when executes?

about declarations:

// worth doing... mystruct ms = new mystruct(0); (int = 0; i< 10000; i++) {     ms.num = i;     // ms }  // ...over this:     (int = 0; i< 10000; i++) {     mystruct ms = new mystruct(i);     // ms }   public struct mystruct {     public int num;      public mystruct(int mynum)     {         num = mynum;     } } 

and instantiation:

for (int = 0; i< 10000; i++) {     mymethod(new mystruct(i));     // mystruct live in scope? } 


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -