digitalmars.D.learn - Sort trouble
- bearophile (12/12) Apr 07 2009 This little program gives me an "Error: Access Violation" on Windows, v1...
- bearophile (8/8) Apr 07 2009 Even just:
- Don (8/18) Apr 07 2009 Confirmed. In fact, any size below 0x8F_FFFF works,
- Don (6/26) Apr 07 2009 And it's caused by the hard-coded
- bearophile (13/13) Apr 07 2009 Smaller version, one sort is enough to cause the error:
- Stewart Gordon (6/8) Apr 07 2009 What is there preventing a built-in sort being implemented to do this?
- Don (3/17) Apr 07 2009 It's more difficult than doing it in a library. For apparently no
- bearophile (4/6) Apr 07 2009 Can you use templates with a statically compiled std lib?
- Jarrett Billingsley (6/10) Apr 07 2009 The template would have to be in the "headers." It wouldn't be
- bearophile (4/7) Apr 08 2009 So far it was not a problem for me.
This little program gives me an "Error: Access Violation" on Windows, v1.042: import std.random: rand; void main() { auto a = new uint[10_000_000]; for (int i = 0; i < a.length; i++) a[i] = rand(); a.sort; a.sort; } Can someone confirm this? Bye, bearophile
Apr 07 2009
Even just: void main() { auto a = new uint[10_000_000]; a.sort; a.sort; } Bye, bearophile
Apr 07 2009
bearophile wrote:Even just: void main() { auto a = new uint[10_000_000]; a.sort; a.sort; } Bye, bearophileConfirmed. In fact, any size below 0x8F_FFFF works, and any size >= 0x8F_FFFF fails. On DMD2.027 as well. void main() { auto a = new uint[0x8F_FFFF]; // smallest size that fails a.sort; a.sort; }
Apr 07 2009
Don wrote:bearophile wrote:And it's caused by the hard-coded byte*[40] stack; // stack in extern (C) long _adSort(Array a, TypeInfo ti) in qsort.d.Even just: void main() { auto a = new uint[10_000_000]; a.sort; a.sort; } Bye, bearophileConfirmed. In fact, any size below 0x8F_FFFF works, and any size >= 0x8F_FFFF fails. On DMD2.027 as well. void main() { auto a = new uint[0x8F_FFFF]; // smallest size that fails a.sort; a.sort; }
Apr 07 2009
Smaller version, one sort is enough to cause the error: void main() { auto a = new uint[0x8F_FFFF]; // smallest size that fails a.sort; } I like the idea of having a built-in sort, but I think it's now better to remove it, and move it into the std lib, so: - It can be replaced/improved/debugged in a simpler way. - It can be more flexible (for example mine accepts an optional "key" mapping function) - It can be a template, so it can be faster (confirmed. I have a sort that is sometimes 3+ times faster). - The overall size and complexity of the language can be a bit lower. - The usage syntax can be almost the same anyway: arr.sort() Bye, bearophile
Apr 07 2009
bearophile wrote: <snip>- It can be more flexible (for example mine accepts an optional "key" mapping function)What is there preventing a built-in sort being implemented to do this?- It can be a template, so it can be faster (confirmed. I have a sort that is sometimes 3+ times faster).<snip> What is there preventing a built-in sort being implemented in this way? Stewart
Apr 07 2009
Stewart Gordon wrote:bearophile wrote: <snip>It's more difficult than doing it in a library. For apparently no benefit at all.- It can be more flexible (for example mine accepts an optional "key" mapping function)What is there preventing a built-in sort being implemented to do this?- It can be a template, so it can be faster (confirmed. I have a sort that is sometimes 3+ times faster).<snip> What is there preventing a built-in sort being implemented in this way? Stewart
Apr 07 2009
Stewart Gordon:Can you use templates with a statically compiled std lib? Bye, bearophile- It can be a template, so it can be faster (confirmed. I have a sort that is sometimes 3+ times faster).What is there preventing a built-in sort being implemented in this way?
Apr 07 2009
On Tue, Apr 7, 2009 at 7:08 PM, bearophile <bearophileHUGS lycos.com> wrote:Stewart Gordon:The template would have to be in the "headers." It wouldn't be compiled into the library file itself. The other problem with a templated sort is that while it's faster than the current built-in sort, it also means there would be a different template instantiation for every element type. Not ideal.Can you use templates with a statically compiled std lib?- It can be a template, so it can be faster (confirmed. I have a sort that is sometimes 3+ times faster).What is there preventing a built-in sort being implemented in this way?
Apr 07 2009
Jarrett Billingsley:The other problem with a templated sort is that while it's faster than the current built-in sort, it also means there would be a different template instantiation for every element type. Not ideal.So far it was not a problem for me. Bye, bearophile
Apr 08 2009