Skip to content

Allocator: fix experimental makeMultidimensionalArray API#5155

Merged
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:fix-allocator-api
Feb 22, 2017
Merged

Allocator: fix experimental makeMultidimensionalArray API#5155
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:fix-allocator-api

Conversation

@wilzbach
Copy link
Contributor

Unfortunately I was away when #4982 was merged (and no one else has raised their voice either).
However, luckily this hasn't been released :)

Imho we can do provide a better API if

  • (1) the type T is always the first parameter (after all that's the only template parameter manually provided by the user)
  • (2) use variadic arguments and thus let the compiler do the hard work for us

FWIW I really don't like the name and would prefer sth. like makeNdarray (that was the name of this method in ndslice.

In short - instead of:

size_t[3] dimArray = [2, 3, 6];
auto mArray = Mallocator.instance.makeMultidimensionalArray!(dimArray.length, int)(dimArray);

let's better write code like this:

auto mArray = Mallocator.instance.makeMultidimensionalArray!int(2, 3, 6);

@wilzbach wilzbach added this to the 2.074.0 milestone Feb 19, 2017
@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
16824 std.experimental.allocator.dispose leaks memory for arrays of more than 1 dimension

An N-dimensional array with individual elements of type T.
*/
auto makeMultidimensionalArray(uint n, T, Allocator)(auto ref Allocator alloc, size_t[n] lengths)
auto makeMultidimensionalArray(T, Allocator, size_t N)(auto ref Allocator alloc, size_t[N] lengths...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. We've had this chataroo in the previous PR - N is not exempt from the usual rules: lowercase for values, uppercase for types. So let's make it lowercase. Thanks!

else
{
alias E = typeof(makeMultidimensionalArray!(n - 1, T)(alloc, lengths[1..$]));
alias E = typeof(makeMultidimensionalArray!(T, Allocator, N - 1)(alloc, lengths[1..$]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces around .. :)

@dlang-bot dlang-bot merged commit f795add into dlang:master Feb 22, 2017
@wilzbach wilzbach deleted the fix-allocator-api branch June 28, 2017 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants