Jump to content

Object Reference


mentalist

Recommended Posts

Hi,

 

I have a class object which needs to draw itself to a canvas and it needs to know which image to draw from. There are various ways I could do this, but... If when I create the object I pass the image to it, is that a copy of that image or just a reference to it?

 

 

Here's a simplified scenario for example:

 

var tileSheet=new Image();tileSheet.src="myImg.png";...var o = new dyn_char();
Should I then do this:
o.img = tileSheet;o.draw();
or this:

o.draw(img);
Which is the more memory efficient way?
Link to comment
https://forums.phpfreaks.com/topic/281788-object-reference/
Share on other sites

I would use the

 

 

o.draw(img);

 

example, simply because the interface doesn't limit you to only drawing one image to your 'tileSheet', i.e. you may in future need to draw 4 images.

 

As for memory footprint, I would assume no to little difference as the same amount of objects are created in the same scope.

Link to comment
https://forums.phpfreaks.com/topic/281788-object-reference/#findComment-1448042
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.