Re: How to store C Arrays as a Property or iVar?



It recurses through the cells in the Array and there could be around 7000 iterations, so I’d rather stick with normal integers.

One thing I was going to ask is that, the value range on each cell is 0 to 10, at the moment its using an “int” to hold this (which I assume is 32 bits), would there be a speed impact if I made it int16 or int8?

All the Best

On 22 Aug 2017, at 12:01, Dave <dave@...> wrote:

Hi Jens,

You solved two problem in one with your last post - thanks a lot!

I had some other information that was being passed back and forth and creating a structure allowed me to solve the Array copying problem and I could add the extra information fields to the struct!

Thanks again,
All the Best

On 18 Aug 2017, at 22:04, Jens Alfke <jens@...> wrote:

On Aug 18, 2017, at 12:07 PM, Dave <dave@...> wrote:

But I get an error if I try to assign or read it, as in:

myArray = _mArray;

You can't assign (or compare) arrays in C/C++. You have two options:

(a) Call memcpy:
memcpy(&myArray, &_mArray, sizeof(myArray));

(b) Wrap a struct around the array, since structs are copyable. Drawback is that you now have to refer to the array as a named field of the struct.
typedef struct {
int [10][10]  a;
} MyArrayType;
MyArrayType myArray;
_mArray = myArray;

(This is a pure C issue, so a book like K&R would be helpful.)


Join { to automatically receive all group messages.