Re: Loading arrays into register
Re: Loading arrays into register
- Subject: Re: Loading arrays into register
- From: Ian Kemmish <email@hidden>
- Date: Fri, 28 Dec 2007 20:49:30 +0000
On 28 Dec 2007, at 8:03 pm, "Simon" <email@hidden> wrote:
Here's some of the code to show what I mean:
sinewavedef* def = defptr; // get access to Sinewave's data
int i;
// load instance variables into registers
double phase = def->phase;
double amp = def->amp;
double pan = def->pan;
double freq = def->freq;
NSArray * xArray = def->xArray;
NSArray * xArrayz = def->xArrayz;
double testArray[100][2] = def->testArray[100][2];
I seem to have no problem with NSArrays (though NMutableArray won't
work), but I need to change the data in the arrays, so these are no
good. I've tried all the variations of the last line I can think
of, including the indeces or not including them, etc. And I can't
find anything about it on the internet. I'm still pretty new to
programming, so there's probably something really obvious I'm missing.
....and later on....
The reason I wanted to use a simple Objective-C array (double
testArray[100][2]) is that the Sinewave class has no autorelease
pool, so I can't use NSMutableArray anyway (I tried to add an
autorelease pool manually, but this seemed to create a lot of
distortion in the sound output).
1) testArray is just a plain old C array. Anything in Objective C
that looks like C behaves like C.
2) double testArray[100][2] is a declaration of a 2 dimensional
array. On the other hand def->testArray[100][2] is a reference to a
scalar item. There are languages which let you initialise arrays by
filling them with a scalar item, but I"m pretty sure Objective C
isn't one of them.
Think carefully about what you're trying to do here. Are you trying
to make a static copy of def->testArray? If so, declare an array and
then copy the contents with memcpy(). Are you trying to make
testArray a pointer to the contents of def->testArray? If so,
declare it as a pointer, not an array.
3) "the Sinewave class has no autorelease pool" doesn't actually mean
anything, so I think you haven't understood what autorelease does.
Objects allocated by [Whatever alloc] don't get put in the current
autorelease pool until you send them an autorelease message; for your
convenience the methods that implement things like [NSMutableArray
arrayWithCapacity: 100] will both allocate the object and send it an
autorelease message on your behalf. What this means for you in
practice is that objects you allocate with [Whatever alloc] have to
be explicitly released (or autreleased), whereas all other objects
have to be explicitly retained if you want them to last between times
around the event loop. In particular, the number of times you'll
ever need to create your own autorelease pool cant be counted on
Captain Hook's fingers.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
Ian Kemmish 18 Durham Close, Biggleswade, Beds
SG18 8HZ
email@hidden Tel: +44 1767 601361 Mob: +44 7952
854387
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden