Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Is it possible to get pointer of class object for fast access.

Subject: Is it possible to get pointer of class object for fast access.

From: BobC Cadenza

Date: 8 Oct, 2010 16:46:05

Message: 1 of 3

I have parts of my code where I have to access a member of a class, that is in a cell array inside the class that is part of another cell array. It would be faster if I can get a pointer to the inside object and use that for the current work instead of having to do multiple redirections multiple times. example below:

class testClass
  properties
     children{100} = childClass;
  end
end

objects{100}.children{50}.doSomething();

Subject: Is it possible to get pointer of class object for fast access.

From: Matt J

Date: 8 Oct, 2010 16:58:04

Message: 2 of 3

"BobC Cadenza" <bobc@mailinator.com> wrote in message <i8nhsc$4ft$1@fred.mathworks.com>...
> I have parts of my code where I have to access a member of a class, that is in a cell array inside the class that is part of another cell array. It would be faster if I can get a pointer to the inside object and use that for the current work instead of having to do multiple redirections multiple times. example below:
>
> class testClass
> properties
> children{100} = childClass;
> end
> end
>
> objects{100}.children{50}.doSomething();

Why not just assign it to something?

obj= objects{100}.children{50}

Remember, all MATLAB objects are in fact copy-on-write pointers under the hood,

http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/

so as long as "objects{100}.children{50}" is never changing, then "obj" is a completely equivalent reference to it.

On the other hand, if "objects{100}.children{50}" does change, then you can make it a handle class, and "obj" will again be a completely equivalent reference to it.

Subject: Is it possible to get pointer of class object for fast access.

From: BobC Cadenza

Date: 8 Oct, 2010 19:04:03

Message: 3 of 3

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i8niis$kh0$1@fred.mathworks.com>...
> "BobC Cadenza" <bobc@mailinator.com> wrote in message <i8nhsc$4ft$1@fred.mathworks.com>...
> > I have parts of my code where I have to access a member of a class, that is in a cell array inside the class that is part of another cell array. It would be faster if I can get a pointer to the inside object and use that for the current work instead of having to do multiple redirections multiple times. example below:
> >
> > class testClass
> > properties
> > children{100} = childClass;
> > end
> > end
> >
> > objects{100}.children{50}.doSomething();
>
> Why not just assign it to something?
>
> obj= objects{100}.children{50}
>
> Remember, all MATLAB objects are in fact copy-on-write pointers under the hood,
>
> http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/
>
> so as long as "objects{100}.children{50}" is never changing, then "obj" is a completely equivalent reference to it.
>
> On the other hand, if "objects{100}.children{50}" does change, then you can make it a handle class, and "obj" will again be a completely equivalent reference to it.

Yes the object is changing, so I will look into handle classes.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us