mono / gtk-sharp

Gtk# is a Mono/.NET binding to the cross platform Gtk+ GUI toolkit and the foundation of most GUI apps built with Mono
http://www.mono-project.com/GtkSharp
Other
426 stars 141 forks source link

Stack alloc #207

Closed Therzok closed 7 years ago

Therzok commented 7 years ago

https://github.com/mono/gtk-sharp/pull/207/commits/60c3220fe47acdaeefbda8e5e4aa77cda3701dca

Means: Faster allocation - not on the heap No more GValueArray wrapper on the heap - plus, no more finalization for it.

Therzok commented 7 years ago

https://github.com/mono/gtk-sharp/pull/207/commits/60c3220fe47acdaeefbda8e5e4aa77cda3701dca https://github.com/mono/gtk-sharp/pull/207/commits/199e4614e19d1dba6b40edf63a6a41d17a212a36

Result in this diff: https://gist.github.com/Therzok/af03aa73dfde604a9f57c0e14db0d589

alanmcgovern commented 7 years ago

Also one thing to keep in mind - there are no guarantees about the contents of stackalloced memory. It looks like we always fully initialize all memory we allocate this way, but if you ever want allocate an extra byte for a null terminator (or whatever) do remember to explicitly write null to that byte!

Therzok commented 7 years ago

The stackallocs are mostly GLib.Value/Utf8String via marshal, so it's safe to assume we don't get uninitialized memory.