Re: Ref counting and mex programmin

13 views
Skip to first unread message
Message has been deleted

Hiho

unread,
Feb 8, 2008, 4:39:54 PM2/8/08
to MathTools

In matlab, when we do A = B, A and B will point to the same matrix.
The copy is postponed to the moment when we modify the data.
Matlab does some 'reference counting' to reduce memory copy.
But if we do A = B + 0., A will be a different matrix than B.

This is really an issue when we do A=B and then pass A as a parameter
to mex function.

Another workaround is to save to mat and reload.

Also, it can be tricky to pass things like A(:, c) to mex-C, because
mex-C may not update
the column c of A as we want.

Thanks Pof. Wu at Stat. UCLA.

On Feb 9, 5:33 am, Hiho <haifeng.g...@gmail.com> wrote:
> In matlab, when we do A = B, A and B will point to the same matrix.
> The copy is postponed to the moment when we modify the data.
> Matlab does some 'reference counting' to reduce memory copy.
> But if we do A = B + 0., I will be a different matrix than J.
>
> This is really a issue when we do A=B and then pass A as a parameter
> to mex function.
>
> Another workaround is to save to mat and reload.
>
> Also, it can be tricky to pass things like A(:, c) to mex-C, because
> mex-C may not update
> the column c of A as we want.
Reply all
Reply to author
Forward
0 new messages