memory allocated when accessing fixed multi-dim array

i am experiencing a very strange issue with a fixed array of int[,]

simply retrieving the contents of the array is causing memory to be allocated, and is causing the garbage collector to be called way too frequently.

for example…

return tilemap[3][4];

this might be invoked 100 times per frame, and is spending about 4kb to do so. am i crazy, or is rhis strangebehavior? should i use singledimensional arrays instead?

4 kb per return or 4kb per 100 frames?

What are you returning?

sorry for not clarifying. you can ignore the return statement.

i am accessing the int[,] array about 100 times per frame, all in the same function. the profiler is showing 4kb of memory allocated each frame by the function, and the garbage collector is forced about once every second. ive tried commenting out the array accessing, and the memory went to 0kb.

The only thing I can think of is that value types are copied… but I’ll bow out to someone with a bit more expertise in this area.

You can always try stackoverflow.

perhaps… but that would be a crazy bug considering int is the most primitive of primitives

I don’t have enough code to see.

Each time you get a int I’d expect to see 4 bytes + overhead stored. You’re already at 400 bytes + overhead.

But I’ve not dug into stack allocations deeply enough to figure out exact overhead, or how it precisely works.

If you’d post the function in question someone might be be able to better assist.

here is a x-post on the iOS forum with some more detailed info

http://forum.unity3d.com/threads/108709-iOS5-and-Unity-Performance?p=721502&viewfull=1#post721502

you can right-click and “view image” to zoom in the profiler screenshots