Understanding memory

BlitzMax Forums/BlitzMax Beginners Area/Understanding memory

Brucey(Posted 2006) [#1]
In, C, if I were to create an array of a certain type :

dContact contact[10];

..would this be allocated in a contiguous block, since in C you can seemingly reference each entry with a simple offset based on the size of dContact.

When creating an equivalent structure in Max...

contact:dContact[] = new dContact[10]

you then subsequently have to instantiate the objects using :

contact[0] = new dContact

Are these objects going to be created in a block order, or placed randomly in memory?


The reason I ask is that I need to pass the array into a C-code routine, and I'm not convinced the C will step through the Max array in the same way as a C one...
??


ImaginaryHuman(Posted 2006) [#2]
The POINTERS TO the instances of the type (dContact) will be in sequential order like a normal array of pointers. Your Contact[] array will contain 10 pointers, stored in sequence. The array doesn't contain any dContact data, only pointers to it.

The actual instances of each New object you create will probably be elsewhere in memory and possibly not in any kind of order.

If you want to have all your instances of dContact be in order, maybe you can use a bank and write the data into specific sequential locations, or make all Fields in your dContact type be of the same type, and just have a big array of that type, split into interpreted groups.


Brucey(Posted 2006) [#3]
Thanks :-)

I thought it might be something like that. Just had to be sure.