c#


Does creating a GUILayoutOption allocate memory?


I want to add some options to a GUI element. For example, like this:
GUILayout.Button("Click me!", GUILayout.Width(someValue));
My question is whether the call to GUILayout.Width() creates a new object on the heap, caches the value, or returns a struct? Because if it creates a new instance each time, then it may be worth creating it once at the beginning instead of creating it at every call to OnGUI(), to avoid excess garbage collection.
It creates a new instance of GUILayoutOption everytime you call GUILayout.Width(). Below are some snippets from Unity source code supporting this:
It creates a new instance on every call to GUILayout.Width()
GUILayout.cs -- Line #903
public static GUILayoutOption Width(float width)
{
return new GUILayoutOption(GUILayoutOption.Type.fixedWidth, width);
}
GUILayoutOption is a class, not a struct
GUILayoutOption.cs -- Line #5
public sealed class GUILayoutOption
On an other note: The call to GUILayout.Button takes a params GUILayoutOption[] so it will implicitly create a new array on each call. If you want to go as far as caching the GUILayoutOption you might aswell cache them in array and pass that to GUILayout.Button().

Related Links

Compress existing PDF using C# programming using freeware libraries
Page_Load does not fire in ASP.NET WebForms
Ways of returning two dictionaries
Calculate some math, error “.” instead of “,”
how can I update elements on the UI thread in a synchronous manner within an async method?
C#'s LINQ and .NET Framework, which one depends on the other?
Where in what files does the binary reference information be saved in VS.NET 2010 web project?
Can I use a type from reflection as a type parameter?
Parallel.ForEach keeps spawning new threads
Check from JQuery if value exists in ViewBag
Stack equivalent to SOS !DumpHeap command
Dropdown list better as ViewBag or part of model C#/.NET MVC4
Abort a webtest if an error occurs
C# SSIS Package User
Passing DataTable to IronPython
Custom XamGrid Columns Databinding Images/Buttons/Tooltips

Categories

HOME
oracle-sqldeveloper
file-upload
itext7
arguments
salesforce-lightning
mailchimp
localhost
confluence-rest-api
glympse
gnuradio
vsixmanifest
samsung-gear-s2
pyodbc
gcloud
guidewire
email-attachments
drush
xmlhttprequest
yui
webseal
internet-explorer-7
smooth-scrolling
jquery-easyui
printf
ampscript
cherrypy
handle
core-animation
suitescript
windows-mobile
ds-5
ocl
lines
key-bindings
ios-autolayout
mplab
cache-control
border-layout
respect-validation
android-databinding
dotnetnuke-module
const
pygraphviz
instances
origami
latency
amazon-rds-aurora
risc
azure-data-catalog
ocamlbuild
togglebutton
g77
flask-socketio
appcmd
ios-keyboard-extension
scanf
msiexec
sqlproj
zsh-completion
networkstream
audiorecord
fadein
tvp
database-project
php-gd
tinymce-plugins
skview
cl.exe
indices
static-files
jsonschema2pojo
qf-test
redmine-plugins
worklight-appcenter
power-management
class-library
cvi
mongoid4
php-amqplib
playing-cards
dynamic-expresso
leap-year
latex-suite
cocotron
mmo
boost.build
report-viewer2010
certificate-revocation
unordered-set
cherokee
session-hijacking
youtube.net-api
quazip
arraycollection
helios
projectgen
html-help-workshop
j++
paperless

Resources

Encrypt Message