Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
September 10, 2002 array bounds checking question. | ||||
---|---|---|---|---|
| ||||
I have read that it is posible to turn it off but is this globaly or can you do it for specific blocks of code as you can in Delphi? I like to leave it on for the most part and just turn it off in specific places where a significant speed benefit is to be had. thanks, chris |
September 10, 2002 Re: array bounds checking question. | ||||
---|---|---|---|---|
| ||||
Posted in reply to chris jones | chris jones wrote:
> I have read that it is posible to turn it off but is this globaly or can you
> do it for specific blocks of code as you can in Delphi? I like to leave it
> on for the most part and just turn it off in specific places where a
> significant speed benefit is to be had.
In those situations you'll want to use the two-register loop as well, so the method kills two birds:
int [] x = new int [45];
for (int *c = x, end = c + x.length; c < end; c ++)
...
Voila, no bounds checking. If you want to index without the bounds check, you can cast:
((int *) x) [l]
There's no way to turn it off for a block of code.
|
September 11, 2002 Re: array bounds checking question. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | "Burton Radons" <loth@users.sourceforge.net> wrote in message news:3D7E80A3.9010608@users.sourceforge.net... > chris jones wrote: > > > I have read that it is posible to turn it off but is this globaly or can you > > do it for specific blocks of code as you can in Delphi? I like to leave it > > on for the most part and just turn it off in specific places where a significant speed benefit is to be had. > > In those situations you'll want to use the two-register loop as well, so the method kills two birds: > > int [] x = new int [45]; > > for (int *c = x, end = c + x.length; c < end; c ++) > ... Hmm. Seems quite an automatic task. Maybe the optimizing compiler could generate similar code if you don't tinker with the array length inside a simple loop. A single bound check before the loop would do. > Voila, no bounds checking. If you want to index without the bounds check, you can cast: > > ((int *) x) [l] > What if we invent a new property: int a = x.unchecked(1); > There's no way to turn it off for a block of code. That's OK. |
September 11, 2002 Re: array bounds checking question. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | This is making me want language support for iterators. Pointers are just a wee bit more dangerous of a thing than you need in this case. And the two register loop is commonplace enough it deserves representation or at least syntax sugar. Sean "Burton Radons" <loth@users.sourceforge.net> wrote in message news:3D7E80A3.9010608@users.sourceforge.net... > chris jones wrote: > > > I have read that it is posible to turn it off but is this globaly or can you > > do it for specific blocks of code as you can in Delphi? I like to leave it > > on for the most part and just turn it off in specific places where a significant speed benefit is to be had. > > In those situations you'll want to use the two-register loop as well, so the method kills two birds: > > int [] x = new int [45]; > > for (int *c = x, end = c + x.length; c < end; c ++) > ... > > Voila, no bounds checking. If you want to index without the bounds check, you can cast: > > ((int *) x) [l] > > There's no way to turn it off for a block of code. |
September 11, 2002 Re: array bounds checking question. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sandor Hojtsy | "Sandor Hojtsy" <hojtsy@index.hu> wrote in message news:almqrr$1tv7$1@digitaldaemon.com... > > "Burton Radons" <loth@users.sourceforge.net> wrote in message news:3D7E80A3.9010608@users.sourceforge.net... > > chris jones wrote: > > > > > I have read that it is posible to turn it off but is this globaly or can > you > > > do it for specific blocks of code as you can in Delphi? I like to leave > it > > > on for the most part and just turn it off in specific places where a significant speed benefit is to be had. > > > > In those situations you'll want to use the two-register loop as well, so the method kills two birds: > > > > int [] x = new int [45]; > > > > for (int *c = x, end = c + x.length; c < end; c ++) > > ... > > Hmm. Seems quite an automatic task. Maybe the optimizing compiler could generate similar code if you don't tinker with the array length inside a simple loop. A single bound check before the loop would do. > > > Voila, no bounds checking. If you want to index without the bounds check, you can cast: > > > > ((int *) x) [l] > > > > What if we invent a new property: > int a = x.unchecked(1); I like the idea, mabey 'unsafe' would be a better keyword, it dicourages use for people who mabey dont know whaht they are doing. Plus there should be a global switch to force bounds checking to aid debuging so you dont have to alter the source code. chris |
September 11, 2002 Re: array bounds checking question. | ||||
---|---|---|---|---|
| ||||
Posted in reply to chris jones | chris jones wrote:
> for people who mabey dont know whaht they are doing. Plus there should be a
> global switch to force bounds checking to aid debuging so you dont have to
> alter the source code.
Array bounds checking is on in debug builds by default.
|
September 11, 2002 Re: array bounds checking question. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:alo40g$1abb$1@digitaldaemon.com... > chris jones wrote: > > > for people who mabey dont know whaht they are doing. Plus there should be a > > global switch to force bounds checking to aid debuging so you dont have to > > alter the source code. > > Array bounds checking is on in debug builds by default. Yes but i mean if it did become posible to have an option to turn bounds checking of for certain pieces of code, it would also be desirable to be able to force them to bounds check in debug builds. As it is its all or nothing. I still want bound checking in release builds but with the option of turning it off for certain bits of code, but still be able to overide that globaly for debug builds. chris |
Copyright © 1999-2021 by the D Language Foundation