megamarc / CsTilengine

C#/Mono binding for Tilengine 2D retro graphics engine
MIT License
20 stars 5 forks source link

Why structs instead classes? #2

Open turric4n opened 6 years ago

turric4n commented 6 years ago

Hi Marc,

I'm reviewing the code and all entities are defined using struct instead classes, there is a specific reason to do this?

Also, I found this library binding :

[DllImport("Tilengine")] private static extern IntPtr TLN_CreateTilemap(int rows, int cols, Tile[] tiles, uint bgcolor, Tileset tileset);

You pass Tileset structure reference directly instead handle pointer. I'm not sure if this is ok, because I didn't test it. Can you confirm?

Thanks

megamarc commented 6 years ago

Hi! Structures are lightweight value types, in most cases they just hold a single integer inside the binding. Classes have the overhead of full memory management, garbage collection ,etc. Being just containers for the underlying memory handlers of the library, I choose structs. I have to check your observation, of course there may be a mistake, thanks for pointing it!

turric4n commented 6 years ago

Hi Marc, Thanks for your response.