Are arrays aligned in memory?

BlitzMax Forums/BlitzMax Programming/Are arrays aligned in memory?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I mean, let's say, if I create an array, will it for example be stored at address 12 in memory (a multiple of 4) or will it be stored at 11, or 9, or 10?

The reason I ask is because I know that on most processors it is faster to read and write memory to aligned addresses. If I read an int from address 12, it might well be faster than reading from address 10 because the CPU might have to read the contents of 8 and 12 to produce a full integer value. Also writing an integer to 10 might require two writes, one to 8 and one to 12.

I recall this was an issue on the 68040 CPU whereby it was preferable to align memory accesses to multiples of 4. It proved to be a lot faster. Similar, some CPU's differ in that if you write 4 sequential bytes to memory, it may be just as fast as writing an integer, due to how the cache works.

What I'm trying to establish is whether I'm taking a performance penalty by using an array based on where in memory it is located.?