Mercurial > projects > dstress
changeset 1579:1802d6b67634
[Issue 1666] New: 64-bit gdc programs cannot allocate large arrays
<david@acz.org>
2007-11-12
http://d.puremagic.com/issues/show_bug.cgi?id=1666
author | thomask |
---|---|
date | Fri, 22 Feb 2008 07:54:04 +0000 |
parents | 10a4a6037695 |
children | df193e7c4e41 |
files | run/m/memory_management_07_A.d run/m/memory_management_07_B.d |
diffstat | 2 files changed, 83 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run/m/memory_management_07_A.d Fri Feb 22 07:54:04 2008 +0000 @@ -0,0 +1,42 @@ +// $HeadURL$ +// $Date$ +// $Author$ + +// @author@ <david@acz.org> +// @date@ 2007-11-12 +// @uri@ http://d.puremagic.com/issues/show_bug.cgi?id=1666 +// @desc@ [Issue 1666] New: 64-bit gdc programs cannot allocate large arrays + +module dstress.run.m.memory_management_07_A; + +int main(char[][] args){ + ubyte x[]; + size_t len = size_t.max - (size_t.max / 32); + + try{ + x.length = len; + }catch(Exception e){ + // "out of memory" Exception + return 0; + } + + // a LOT of memory (maybe someone cheated *g*) + if(len != x.length){ + assert(0); + } + + // try to defeat "smart" cheaters + size_t step = 4096 - args.length; + for(size_t i = 0; i < len; i += step){ + x[i] = i & 0xFF; + } + + step = 4096 - ((args[0].length / 1000 + 1) % 13); + for(size_t i = 0; i < len; i += step){ + if((i & 0xFF) != x[i]){ + assert(0); + } + } + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run/m/memory_management_07_B.d Fri Feb 22 07:54:04 2008 +0000 @@ -0,0 +1,41 @@ +// $HeadURL$ +// $Date$ +// $Author$ + +// @author@ <david@acz.org> +// @date@ 2007-11-12 +// @uri@ http://d.puremagic.com/issues/show_bug.cgi?id=1666 +// @desc@ [Issue 1666] New: 64-bit gdc programs cannot allocate large arrays + +module dstress.run.m.memory_management_07_B; + +int main(char[][] args){ + ubyte x[]; + size_t len = 1 << 29; + + try{ + x.length = len; + }catch(Exception e){ + // "out of memory" Exception + return 0; + } + + if(len != x.length){ + assert(0); + } + + // try to defeat "smart" cheaters + size_t step = 4096 - args.length; + for(size_t i = 0; i < len; i += step){ + x[i] = i & 0xFF; + } + + step = 4096 - ((args[0].length / 1000 + 1) % 13); + for(size_t i = 0; i < len; i += step){ + if((i & 0xFF) != x[i]){ + assert(0); + } + } + + return 0; +}