c++ - Safe some memory when passing and assigning -


i new c++ (coming c#) , want memory stuff right beginning.
in following snipped variable of type worldchunkcoordinates passed value inline constructor of worldchunk , passed coordinates assigned worldchunk::coordinates, believe copy operation well.
(copy-assignment operation?)

if assumptions correct kinda stupid, because copy instance twice. think more performant if pass value , assign reference pointer. worldchunk::coordinates not pointer neither reference.

worldchunk(worldchunkcoordinates coordinates) {    worldchunk::coordinates = coordinates; } 

is there way safe programm copying instance twice?
if so, how?

also: is assigning = copy operation default?
and: how should know specific class may have copy assignment operation copies reference?

its known , solved problem, called initializer list (not confused container). looks like

 worldchunk(worldchunkcoordinates coordinates) : coordinates(coordinates){}  

consider using lower case letters variable names.

you use

 worldchunk(const worldchunkcoordinates &coordinates) : coordinates(coordinates){}  

but not obvious dereferencing faster copying, when taking compiler optimizations account.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -