da Silva, Joe wrote:
So it seems this issue has arisen, because someone has decided to create 'getmemory' and 'freememory' routines, which simulate the functionality of 'new' and 'dispose' - strange!!! <g>
Not quite. In BP (which the code was originally written for AFAIUI), `New' does not support run-time variable sizes (there are no schema types or similar in BP). So every allocation of variable size has to be done via GetMem, and freed via FreeMem. Furthermore, BP does not keep track of the size allocated by itself, and FreeMem must be passed the correct size. So this stuff makes kind of sense for BP, but is quite unnecessary for GPC.
Nevertheless, I can't see any reason why the sample code presented should fail, unless there is also some issue with accessing of record fields and their address alignment, right?
Apart from the 2 vs. 4 bytes (i.e., SizeOf (Integer/Word/SizeType/...)) problem, there can be alignment problems. The Intel IA32 processors allow misaligned access, though with a speed penalty, other processors will simply crash.
With a "shift" of 2 bytes, you're sure to get alignment problems. With a shift of 4 bytes (as would be reasonable for GPC, see above), you might get problems with large types (LongInt, real types). Not sure what diffferent processors require, but I wouldn't be surprised if such code crashes on non-IA32 machines.
Frank