Array length & allocation question

Oskar Linde oskar.lindeREM at OVEgmail.com
Mon Jun 12 16:14:24 PDT 2006


Sean Kelly skrev:

> Perhaps D arrays simply need a reserve property?

Something like this ought to work:

template reserve(ArrTy,IntTy) {
         void reserve(inout ArrTy a, IntTy size) {
                 if (size > a.length) {
                         size_t old_length = a.length;
                         a.length = size;
                         a = a[0..old_length];
                 }
         }
}


usage:

arr.reserve(1000);

/Oskar



More information about the Digitalmars-d-learn mailing list