Re: Creating a logical matrix in a mex-file
- From: Fred <fred64_2006@xxxxxxxxxxxxx>
- Date: Thu, 16 Mar 2006 06:17:43 -0500
Christopher Hulbert wrote:
Generate the array using one dimension of 0 or rank 0. This will
not allocate
the data for the array. Then use mxMalloc to allocate the memory
*without*
initialization. Use mxSetData to set the data of the array to the
allocated
memory. This would avoid the initialization of the memory.
Ok. I not quite sure how to do that. For example how do I
transform
int m = 1000;
int n = 1000;
mxArray *A_ptr;
A_ptr = mxCreateLogicalMatrix(m, n);
bool *A;
A = mxGetPr(A_ptr);
into code which does not initialize the elements of A.
My guess would be
int m = 1000;
int n = 1000;
mxArray *A_ptr;
A_ptr = mxMalloc(m*n+2);
mxSetM(A_ptr, m);
mxSetN(A_ptr, n);
bool *A;
A = mxGetPr(A_ptr);
I really have no idea how much memory to allocate. Since there a
differnce between a pointer to an mxArray and a pointer to the data
of an mxArray, and since arrays are stored as vectors, there should
be some extra bytes storing
the dimension and size of the array. Using mxMalloc I would guess I
have to take that into account.
Another unanswered question is whether I am chasing a ghost here
trying to avoid initialization.
Thank you all for your patience and help with my neverending
questions on mex-files.
Fred
.
- Follow-Ups:
- Re: Creating a logical matrix in a mex-file
- From: Peter Boettcher
- Re: Creating a logical matrix in a mex-file
- References:
- Creating a logical matrix in a mex-file
- From: Fred
- Re: Creating a logical matrix in a mex-file
- From: Fred
- Re: Creating a logical matrix in a mex-file
- From: Christopher Hulbert
- Creating a logical matrix in a mex-file
- Prev by Date: Re: For loop vectorization
- Next by Date: Re: Model for PWM inverter fed Induction Motor
- Previous by thread: Re: Creating a logical matrix in a mex-file
- Next by thread: Re: Creating a logical matrix in a mex-file
- Index(es):
Relevant Pages
|