TStringField Memory Alignment Trade-off: ARM64 Production vs x86 Development
0 reputation · 03 Aug 2024, 01:44 UTC
0 reputation · 03 Aug 2024, 01:44 UTC
TStringField components require 4-byte memory alignment on x86 development machines but enforce 8-byte alignment on ARM64 production servers, causing runtime field access violations when identical data modules are deployed.
The FireDAC TStringField class internally calculates buffer offsets based on compile-time target architecture. Local development targets Win64-x86 with 4-byte alignment, while production deployments to ARM64 Windows Server 2019 require 8-byte alignment for optimal performance. This discrepancy manifests as EAccessViolation exceptions when accessing field values through the Items property.
FireDAC's design-time field buffer allocation follows the target platform's native alignment requirements as documented in Embarcadero's FireDAC Architecture Guide (version 10.4 Sydney). The TStringField.AllocRecordBuffer method adjusts alignment based on System.Character's platform-specific SizeOf calculations.
Recompile the data module for the ARM64 target platform. Do not use a runtime alignment override; FireDAC does not document a public SetFieldAlignment API for TStringField, and modifying field-buffer offsets while the application is running risks memory corruption. FDMemTable.BufferChunksize is also not the correct mechanism, because it controls internal memtable row-chunk granularity, not TStringField alignment.
Likely explanation: field-buffer offsets are calculated at compile time. A build targeting x86 embeds offsets based on that architecture's alignment rules, while an ARM64 build uses ARM64 rules. Deploying the x86 build to ARM64 can produce mismatched offsets that surface as EAccessViolation when field values are accessed through Items.
Confirmed facts: BufferChunksize affects FDMemTable row-chunk sizing only and does not normalize alignment across processor architectures. Alignment behavior varies by compiler and FireDAC version, so version-specific claims should be checked against your installed RAD Studio release before treating them as settled.
Is the failing build a 32-bit x86 executable running under emulation on ARM64, or a native x64 build? This determines whether the 4-byte versus 8-byte alignment premise in the question applies to your deployment.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.