c# - IEnumerable state machine larger than return List -


i'm not sure has huge effect on modern day computers.

however, interesting know.

i've been reading these resources trying find out if on head of using iterator state machine larger returning list. emphasis not on ability lazy load, in example makes no odds on when evaluated.

resoures:

now last resource closest.

it comes down if know length of list constant is:

is footprint of ienumerable<t> state machine > list<t>

so:

public void ienumerable<customclass> getcustoms(string input) {     foreach (var ch in input.tochararray())         yield return new customclass(ch); } 

does state machine create larger overhead than:

public void ienumerable<customclass> getcustoms(string input) {     var result = new list<customclass>(input.length);      foreach(var ch in input.tochararray())         result.add(new customclass(ch));      return result; } 

obviously contrived example. illustrates point.

i can imagine, if there lot of preprocessing happening before iteration in methods, state machine contain pre processing overhead.

logic allocation of list memory far less allocation ienumerable state machine memory.

obviouosly bigger enumeration, more starts flip other way , ienumerable state machine becomes smaller foot print.

are these observations correct?


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -