On Tuesday, 6 May 2014 at 00:10:36 UTC, Andrei Alexandrescu wrote:
So I'm looking at creation functions and in particular creation functions for arrays.

1. Follow the new int[n] convention:

auto a = allok.make!(int[])(42);
assert(a.length == 42);
assert(a.equal(repeat(0, 42));

2. Follow the [ literal ] convention:

auto a = allok.make!(int[])(42);
assert(a.length == 1);
assert(a[0] == 42);

For the second option, to create longer arrays:

auto a = allok.make!(int[])(42, 43, 44);
assert(a.length == 3);
assert(a.equal(iota(42, 45));

Nice ways to repeat things:

auto a = allok.make!(int[])(42, repeat(43, 5), 44);

And even nice ways to create holes for efficiency:

auto a = allok.make!(int[])(42, uninitialized(5), 44);


Destroy.

Andrei

The first option should have better performance(write fast code). The second method allows more expressiveness(write code fast). I generally like expressiveness, but direct memory allocation is low level programming, so fast code should take precedence.
    • Re: API Orvid King via Digitalmars-d
  • Re: API bearophile via Digitalmars-d
    • Re: API H. S. Teoh via Digitalmars-d
  • Re: API Brian Schott via Digitalmars-d
  • Re: API Walter Bright via Digitalmars-d
    • Re: API MattCoder via Digitalmars-d
    • Re: API Andrei Alexandrescu via Digitalmars-d
      • Re: API Walter Bright via Digitalmars-d
        • Re: API Andrei Alexandrescu via Digitalmars-d
        • Re: API monarch_dodra via Digitalmars-d
  • Re: API Idan Arye via Digitalmars-d
  • Re: API Brad Anderson via Digitalmars-d
    • Re: API bearophile via Digitalmars-d
  • Re: API ed via Digitalmars-d
  • Re: API Steven Schveighoffer via Digitalmars-d
  • Re: API Yota via Digitalmars-d
  • Re: API Andrei Alexandrescu via Digitalmars-d
  • Re: API Dmitry Olshansky via Digitalmars-d
    • Re: API Steven Schveighoffer via Digitalmars-d
  • Re: API Byron via Digitalmars-d

Reply via email to