Alvaro Fernandez said:
> The spread()... expression is an outer product which is packed into a
> vector.
> I assume that a matrix is created on the heap dynamically to hold the
Not necessarily on the heap, can be on the stack.
> results
> of the outerproduct, and then passed by reference into SetC. I also
> assume that
> once SetC terminates, this temporary matrix normally disappears. If so,
> does my
> referencing it with a pointer keep it from disappearing, or will M%c be
> pointing at
> nothing once SetC finishes? At this moment, in the actual code I took
Once SetC finishes, M%c will be undefined (anything goes).
You could get a program crash, wrong results, or even the right result
(though getting the right result is pretty unlikely).
> this example from,
> I copy c into M%c after suitably allocating M%c. I am trying to avoid
> that.
Your only real chance of avoiding copying is to assign the PACK expression
into a variable in the first place. I also note that your PACK does not seem
to be doing anything useful anyway - perhaps the "real code" differs, but
one in your example could be replaced by RESHAPE.
Cheers,
--
...........................Malcolm Cohen, NAG Ltd., Oxford, U.K.
([log in to unmask])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|