Re: Simple Array
Re: Simple Array
- Subject: Re: Simple Array
- From: Ondra Cada <email@hidden>
- Date: Thu, 20 Sep 2001 18:40:23 +0200
Nicolai,
>
>>>>> Nicolai (N) wrote at Thu, 20 Sep 2001 18:21:30 +0200:
N> Here is maybe a very easy question:
N>
N> In C++ I declare a variable like this:
N> double * pDoubleArray;
N> Allocation:
N> pDoubleArray = new double[size];
N> Initialization:
N> pDoubleArray[position] = dNumber;
N> Deallocation:
N> delete [] pDoubleArray;
N> pDoubleArray = NULL;
N>
N> Does anyone know how I do the same in ObjC???
First, DON'T DO THAT -- use NS(Mutable)Array instead.
If you insist, though, it is almost the same, but for the new/delete
operators which must be replaced by the standard ANSI malloc or calloc/free:
double * pDoubleArray;
pDoubleArray = calloc(size, sizeof(*pDoubleArray)); // sizeof(double) would
work as well, but this is better if you happen to change the source
pDoubleArray[position] = dNumber;
free(pDoubleArray);
pDoubleArray = NULL;
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc