Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mex compiling error
Date: Wed, 23 Sep 2009 12:08:21 +0000 (UTC)
Organization: Universit&#228;t Bern
Lines: 22
Message-ID: <h9d33l$glg$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> <h984l4$ft2$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 1253707701 17072 172.30.248.35 (23 Sep 2009 12:08:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 Sep 2009 12:08:21 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1490572
Xref: news.mathworks.com comp.soft-sys.matlab:572305


"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <h984l4$ft2$1@fred.mathworks.com>...
> "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

Thanks James, if I initialize it as you said, it works absolutely perfect!