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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -