Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mex compiling error
Date: Mon, 21 Sep 2009 15:04:04 +0000 (UTC)
Organization: Boeing
Lines: 19
Message-ID: <h984l4$ft2$1@fred.mathworks.com>
References: <h97rq1$3nc$1@fred.mathworks.com> <d102bc34-8206-4f28-b692-281de004e561@f33g2000vbm.googlegroups.com> <h9803b$fkp$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1253545444 16290 172.30.248.35 (21 Sep 2009 15:04:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 21 Sep 2009 15:04:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:571810


"Stephan " <schmutz@pyl.unibe.ch> wrote in message <h9803b$fkp$1@fred.mathworks.com>...
> 
>  So how can I initialize the array at run time?

One method using the API functions:

int const nrOfFrames = (int)mxGetScalar(prhs[0]); // Input variable, nr. of frames to load 
// Put it checks here for valid nrOfFrames value
BYTE **pData; // Used for allocated array of Pointers for image data
pData = (BYTE **) mxMalloc(nrOfFrames*sizeof(*pData));
if( pData == NULL ) { // not really needed since MATLAB will exit the mex function if you run out of memory
    mexErrMsgTxt("Unable to allocate pData.");
}
// other code here to use pData
mxFree(pData); // free the memory when you are done with it

P.S. Variable Length Arrays, where the array size is determined at run-time, *are* part of the current C Standard, but they are *not* part of the C++ standard. Having said that, many popular C compilers such as Microsoft Visual C (at least up to 8 ... I haven't tried 9 yet) and the lcc that ships with MATLAB, do not support Variable Length Arrays yet.

James Tursa