Why 16Mib static array size limit?
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Tue Aug 16 21:21:01 PDT 2016
On 8/15/2016 6:28 PM, Ali Çehreli wrote:
> void main() {
> auto p = arr.ptr;
>
> foreach (j; 0 .. 100) {
> foreach (i; 0..arr.length) {
> version (POINTER) {
> p[i] += cast(ubyte)i;
> }
> else {
> arr[i] += cast(ubyte)i;
> }
> }
> }
> }
When accessing global arrays like this, cache the address of the data in a local
variable. This will enable the compiler to enregister it. Putting global data in
registers is problematic because any assignment through a pointer could change
it, so the compiler takes a pessimistic view of it.
Your POINTER version does cache the pointer, but arr.length needs to be cached
as well.
More information about the Digitalmars-d
mailing list