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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -