question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IEnumerable vs Array

See original GitHub issue

Entitas heavily uses arrays. Most of the api also expose this fact. Some functions return copies of the internal data structures with .ToArray() to protect the internal state from external modification which is very important.

I was wondering if I should change the whole api to IEnumerable to reduce the amount of converting to arrays. The user can call .ToArray if need otherwise we might be able to save some conversions. I haven’t checked the code and the consequences yet, but it might be a good idea.

What are your opinions? Please share below

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
sschmidcommented, Apr 26, 2017

Exactly. Returning IEnumerables might keep us flexible which data structures we use and if we want to do caching or not. Returning IEnumerable prevents (not 100%) you from modifying the collection too and encourage to use copies with collection.ToArray() when you actually need to change things

0reactions
paraboxxcommented, Apr 27, 2017

Just passing in a raw IEntity[] array will lead to a lot of unnecessary copying. I once added some performance counters to find out how often I get cached results vs a fresh allocation over all groups in my game and 98% was cached results.

So I would go one step further and add an actual cache class that the user can pass in and that gets registered with the group. The group can then invalidate the caches like it does invalidate it’s internal cache with the difference that the external cache just sets a flag or something and doesn’t need to reallocate the next time it’s used. The user would be responsible for checking the flag and refreshing the cache before it’s actually used.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the difference between IEnumerable and Array, IList ...
IEnumerable is a behavior while Array is a data structure(Contiguous collection of elements with fixed size, facilitating accessing elements by ...
Read more >
C# IEnumerable vs List and Array
“IEnumerable describes behaviour, while List is an implementation of that behaviour. When you use IEnumerable, you give the compiler a chance to ...
Read more >
IEnumerable Versus List what is main reason to choose ...
In general iterators (IEnumerable) is a pattern to work with data, but array (or List) is iself a data structure that stores state....
Read more >
List vs IEnumerable vs IQueryable vs ICollection ...
This article is one of the first sources (with complete and clear comparison) about data structure, Array, ArrayList, List, IList, ...
Read more >
Ordered enumeration: IEnumerable or Array (in C#)?
IEnumerable declares that the collection you have can be enumerated ; it doesn't imply anything about the content. This isn't a bad thing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found