Trying to make FreeList Allocator example compile

2018-10-08 Thread Per Nordlöw via Digitalmars-d-learn
I'm trying to compile the example import std.experimental.allocator.building_blocks.free_list : FreeList; theAllocator = allocatorObject(FreeList!8()); at https://dlang.org/phobos/std_experimental_allocator.html but fails first because of missing import import std.experimental.a

Details on how aggregates are constructed with `new` and later destroyed by the GC

2018-10-08 Thread Per Nordlöw via Digitalmars-d-learn
I want to understand how calls to `new` for classes and structs are lowered by the compiler and druntime to a GC-allocation (specifically how the `ba`-argument bits are determined) followed by an initialization using default constructor or via a user-defined constructor called using arguments t

Re: DMD release build being faster than debug!

2018-10-05 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 5 October 2018 at 16:57:03 UTC, Seb wrote: Yeah BUILD more or less only defines in which folder the binaries will be stored as the default BUILD was RELEASE historically and the real release build can take a while and shouldn't be used by default (bad newcomer experience). We tried t

Re: DMD release build being faster than debug!

2018-10-05 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 5 October 2018 at 14:11:22 UTC, Per Nordlöw wrote: Are there more DMD switches other than `BUILD=release` I need to activate to produce the fastest possible compiler binary? Apart for compiling it with LDC, that is. Ahh, that wasn't so hard to find once I looked inside the correct

DMD release build being faster than debug!

2018-10-05 Thread Per Nordlöw via Digitalmars-d-learn
I just noticed that building DMD~master via make -f posix.mak BUILD=debug currently takes 3.2 secs while building it via make -f posix.mak BUILD=release takes only 3.0 secs on my Ubuntu 18.04 64-bit machine! Are there more DMD switches other than `BUILD=release` I need to activate to

Re: GC page and block metadata storage

2018-10-02 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 09:43:02 UTC, thedeemon wrote: I guess you would want to scan the metadata without thrashing all the pages. Keeping metadata together compactly is good for cache. Can you briefly elaborate on what use case(s) you hade in mind when you wrote this?

Re: Linking with a non-default druntime

2018-10-02 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 16:20:52 UTC, Basile B. wrote: This works https://github.com/BBasile/druntime/pull/1. Not sure if it will be useful. Ahh, thanks! I've just found my own way of iterating via a script at https://github.com/nordlow/scripts/blob/master/dmd-own that (re)compiles

GC page and block metadata storage

2018-10-02 Thread Per Nordlöw via Digitalmars-d-learn
Should a new fresh GC for D store block metadata inside the page itself or in a (pool) structure separate from the page? I'm already aware of Dmitry's suggestion to separate value-type pools from pools of types possibly containing addresses.

Re: Linking with a non-default druntime

2018-10-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 October 2018 at 08:27:54 UTC, Basile B. wrote: I think so. Apparently it's registered with a string, e.g "manual" and you pass a special druntime option with your program to select. Actually i would be interested to make the interface with assignable handlers since you don't seem t

Re: Linking with a non-default druntime

2018-10-01 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 30 September 2018 at 19:53:02 UTC, Basile B. wrote: this way you can very easily change-compile-test, without recompiling the whole runtime and phobos each time. Ok, thanks. Is it possible to register an extra GC in a separate program by overriding the logic in `gc.proxy` in drunti

Linking with a non-default druntime

2018-09-30 Thread Per Nordlöw via Digitalmars-d-learn
How can I link my dmd-compiled program with a specific version of the druntime? I need this when experimenting with a new GC.

Re: Performance of GC.collect() for single block of `byte`s

2018-09-28 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 24 September 2018 at 14:31:45 UTC, Steven Schveighoffer wrote: It's not scanning the blocks. But it is scanning the stack. Each time you are increasing the space it must search for a given *target*. It also must *collect* any previous items at the end of the scan. Note that a collec

Re: Performance of GC.collect() for single block of `byte`s

2018-09-28 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 24 September 2018 at 14:31:45 UTC, Steven Schveighoffer wrote: ever growing task. And really, this isn't that much (at the end, you are still less than 1ms). Compared to GCs like Go's this is an enormous latency for a single allocation of value elements.

Re: Performance of GC.collect() for single block of `byte`s

2018-09-28 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 28 September 2018 at 09:14:18 UTC, Per Nordlöw wrote: How is it possible for the GC to be 500-1000 times slower than a malloc-free call for a single array containing just bytes with no indirections for such a simple function!!!? I really don't understand this... I change the code

Re: Performance of GC.collect() for single block of `byte`s

2018-09-28 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 24 September 2018 at 14:31:45 UTC, Steven Schveighoffer wrote: Why is the overhead so big for a single allocation of an array with elements containing no indirections (which the GC doesn't need to scan for pointers). It's not scanning the blocks. But it is scanning the stack. Ok,

Performance of GC.collect() for single block of `byte`s

2018-09-24 Thread Per Nordlöw via Digitalmars-d-learn
The code import std.stdio; void main(string[] args) { import std.datetime.stopwatch : benchmark; import core.time : Duration; import core.memory : GC; immutable benchmarkCount = 1; foreach (const i; 0 .. 10) { const byteCount = i*100_000_000; const array

Destructor and postblit with scope qualifier

2018-09-20 Thread Per Nordlöw via Digitalmars-d-learn
What effect does the scope qualifier have on a destructor such as https://github.com/atilaneves/automem/blob/master/source/automem/vector.d#L92 and a postblit such as https://github.com/atilaneves/automem/blob/master/source/automem/vector.d#L86 ?

Re: Fast linear search for non-null key in slice of Nullable(T, T.max)

2018-09-16 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 16 September 2018 at 16:50:32 UTC, Neia Neutuladh wrote: On Sunday, 16 September 2018 at 16:28:20 UTC, Per Nordlöw wrote: If I have alias N = Nullable!(T, T nullValue) fed as template parameter to another template how can I at compile-time get the `nullValue` ? import std.trai

Fast linear search for non-null key in slice of Nullable(T, T.max)

2018-09-16 Thread Per Nordlöw via Digitalmars-d-learn
If I have alias N = Nullable!(T, T nullValue) fed as template parameter to another template how can I at compile-time get the `nullValue` ? I need this to implement fast linear search over a slice of type Nullable!(ulong, ulong.max)[] searching for a non-null key without needing to

Re: ldc2 crashes when trying to compile my app

2018-09-01 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 1 September 2018 at 20:35:52 UTC, Per Nordlöw wrote: On Saturday, 1 September 2018 at 19:52:14 UTC, kinke wrote: `_Z7DtoLValP6DValue` may be suitable... Is this a C++-symbol? import core.demangle; demangle("_Z7DtoLValP6DValue") returns the same string... It's C++. Demangled v

Re: ldc2 crashes when trying to compile my app

2018-09-01 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 1 September 2018 at 19:52:14 UTC, kinke wrote: `_Z7DtoLValP6DValue` may be suitable... Is this a C++-symbol? import core.demangle; demangle("_Z7DtoLValP6DValue") returns the same string...

ldc2 crashes when trying to compile my app

2018-09-01 Thread Per Nordlöw via Digitalmars-d-learn
per:~/Work/knet] $ dub run --compiler=ldmd2 --build=release-nobounds The determined compiler type "ldc" doesn't match the expected type "dmd". This will probably result in build errors. WARNING: A deprecated branch based version specification is used for the dependency gmp-d. Please use numbered

Re: Cannot make sense of LLD linker error with ldc 1.11.0

2018-08-30 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 30 August 2018 at 16:12:24 UTC, kinke wrote: Nope, I now think this is more likely an issue with the default config (etc/ldc2.conf). It contains a new section for WebAssembly, which specificies `-link-internally`, which seems to be wrongly used for non-WebAssembly too in your case.

Cannot make sense of LLD linker error with ldc 1.11.0

2018-08-30 Thread Per Nordlöw via Digitalmars-d-learn
Recently the benchmark https://github.com/nordlow/phobos-next/tree/master/benchmarks/containers/dub.sdl run as dub run --compiler=ldc2 --build=release has started to fail as Performing "release" build using ldc2 for x86_64. phobos-next ~master: target for configuration "library" is up to

Re: Fast OpenGL-based visualization engine mainly for animated two-dimensional graphs

2018-08-24 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 24 August 2018 at 14:34:46 UTC, Per Nordlöw wrote: On Friday, 24 August 2018 at 14:03:08 UTC, drug wrote: imgui, but now I'm replacing it by nuklear. Is nuklear a software project that can be found somewhere? Ahh, I presume you mean - https://github.com/vurtun/nuklear - https://g

Re: Fast OpenGL-based visualization engine mainly for animated two-dimensional graphs

2018-08-24 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 24 August 2018 at 14:03:08 UTC, drug wrote: imgui, but now I'm replacing it by nuklear. Is nuklear a software project that can be found somewhere?

Fast OpenGL-based visualization engine mainly for animated two-dimensional graphs

2018-08-24 Thread Per Nordlöw via Digitalmars-d-learn
Is anybody working on a D-based really fast OpenGL-based visualization engine that supports tessellation of 2d primitives on the GPU? For instance, if I want to animate a huge amount of circles (in a 2d-graph) and I would like to only have to send an array of centers and radiuses and optional

Re: tryTo: non-throwing variant of std.conv.to

2018-08-15 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 10:38:23 UTC, Jonathan M Davis wrote: Would it be sane to add these to std.conv alongside existing std.conv.to so that underlying logic in std.conv.to can be reused? If so, AFAICT, existing std.conv.to should be implemented on Put something together to get ear

Re: tryTo: non-throwing variant of std.conv.to

2018-08-15 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 09:26:26 UTC, Seb wrote: If so, AFAICT, existing std.conv.to should be implemented on top of std.conv.tryTo. Well, for now you can use `ifThrown` from std.exception: https://dlang.org/phobos/std_exception.html#ifThrown --- "foo".to!int.ifThrown(42) But the wh

tryTo: non-throwing variant of std.conv.to

2018-08-15 Thread Per Nordlöw via Digitalmars-d-learn
Have anybody thought about non-throwing variants of std.conv.to typically named `tryTo` similar to what Folly https://github.com/facebook/folly/blob/master/folly/docs/Conv.md#non-throwing-interfaces does, for instance, as tryTo(str).then([](int i) { use(i); }); ? Would it be sane to add

Re: Better diagnostics for null classes dereferencing

2018-07-11 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 11 July 2018 at 04:17:49 UTC, Seb wrote: https://github.com/dlang/druntime/pull/2249 Thanks!

Re: Better diagnostics for null classes dereferencing

2018-07-10 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 19:27:07 UTC, Steven Schveighoffer wrote: import etc.linux : registerMemoryErrorHandler; Needs to be: import etc.linux.memoryerror : registerMemoryErrorHandler;

Re: Better diagnostics for null classes dereferencing

2018-07-10 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 10 July 2018 at 19:27:07 UTC, Steven Schveighoffer wrote: On 7/10/18 3:01 PM, Per Nordlöw wrote: Is it possible to change run-time behaviour of null-class dereferencing, on Linux, so that it gives some other diagnostics than: Program exited with code -11 Does DMD and LDC provide

Better diagnostics for null classes dereferencing

2018-07-10 Thread Per Nordlöw via Digitalmars-d-learn
Is it possible to change run-time behaviour of null-class dereferencing, on Linux, so that it gives some other diagnostics than: Program exited with code -11 Does DMD and LDC provide different alternatives here?

Re: Move and CTFE

2018-06-21 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 21 June 2018 at 20:15:42 UTC, Stefan Koch wrote: To give some more context here: CTFE is the most well tested feature in dmd. So there is no room for sloppiness or functional differences! As you previously mentioned the newCTFE engine works on a completely different basis then the

Re: Nothrow std.conv.to with explicit default value

2018-06-21 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 20 June 2018 at 14:39:48 UTC, Per Nordlöw wrote: Is there a way to avoid compile-time-string-concat plus mixin here? Using __traits(getMember, ...) should compile faster, right? T toDefaulted(T)(scope const(char)[] value, T defaultValue) @safe pure nothrow @nogc if (is(T == enu

Re: Nothrow std.conv.to with explicit default value

2018-06-20 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 20 June 2018 at 09:54:29 UTC, Per Nordlöw wrote: T toDefaulted(T)(scope const(char)[] value, T defaultValue) @safe pure nothrow @nogc if (is(T == enum)) { switch (value) { static foreach (index, member; __traits(allMembers, T)) { case

Re: Nothrow std.conv.to with explicit default value

2018-06-20 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 20 June 2018 at 09:37:00 UTC, Per Nordlöw wrote: AFAICT, string-to-enum-conversion must include a switch containing a static foreach over all the enumerators, right? My suggestion for nothrow @nogc string-to-enum conversion with default value T toDefaulted(T)(scope const(char)

Re: Nothrow std.conv.to with explicit default value

2018-06-20 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 20 June 2018 at 09:52:04 UTC, Per Nordlöw wrote: My suggestion for nothrow @nogc string-to-enum conversion with default value T toDefaulted(T)(scope const(char)[] value, T defaultValue) @safe pure nothrow @nogc if (is(T == enum)) { switch (value) {

Re: Nothrow std.conv.to with explicit default value

2018-06-20 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 20 June 2018 at 09:27:14 UTC, Per Nordlöw wrote: On Monday, 18 June 2018 at 21:10:03 UTC, Steven Schveighoffer wrote: It just means re-doing std.conv.to, which is pretty hairy, but also pretty well-organized. Ok. Where in std.conv do the string-to-enum conversions take place?

Re: Nothrow std.conv.to with explicit default value

2018-06-20 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 18 June 2018 at 21:10:03 UTC, Steven Schveighoffer wrote: It just means re-doing std.conv.to, which is pretty hairy, but also pretty well-organized. Ok. Where in std.conv do the string-to-enum conversions take place?

Nothrow std.conv.to with explicit default value

2018-06-18 Thread Per Nordlöw via Digitalmars-d-learn
I have a nothrow variant of std.conv.to defined as follows: T toDefaulted(T, S, U)(S value, /*lazy*/ U defaultValue) if (is(typeof(() { T r = defaultValue; }))) // TODO use std.traits.isAssignable!(T, U) ? { try { import std.conv : to; return value.to!T; } catch

Naming conventions for export and import members of a struct

2018-05-27 Thread Per Nordlöw via Digitalmars-d-learn
The integer type in gmp-z just got export (binary serialization) support at https://github.com/nordlow/gmp-d/pull/8 Next up is import (binary deserialization). What's the preferred D-style naming convention for wrapping exporting and exporting to binary formats? I'm thinking Z.to!(U[])

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-10 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 21:09:12 UTC, Meta wrote: It's a context pointer to the enclosing function/object/struct. Mark the struct as static to get rid of it. Ok, but why an extra void* for `S.tupleof` and not for `T.tupleof` which is also scoped inside a unittest?

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-09 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 17:52:48 UTC, Meta wrote: I wasn't able to reproduce it on dmd-nightly: https://run.dlang.io/is/9wT8tH What version of the compiler are you using? Ahh, the struct needs to be in a unittest block for it to happen: struct R { @disable this(this); int* _ptr;

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-09 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 14:36:38 UTC, Per Nordlöw wrote: On Wednesday, 9 May 2018 at 14:34:02 UTC, Per Nordlöw wrote: On Wednesday, 9 May 2018 at 14:20:41 UTC, Per Nordlöw wrote: If so, we can temporarily modify the trait to exclude the last `void*` member of the `S.tuple`. Given that it's

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-09 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 14:34:02 UTC, Per Nordlöw wrote: On Wednesday, 9 May 2018 at 14:20:41 UTC, Per Nordlöw wrote: If so, we can temporarily modify the trait to exclude the last `void*` member of the `S.tuple`. Given that it's always added as the last member. Also note that pragma

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-09 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 14:20:41 UTC, Per Nordlöw wrote: If so, we can temporarily modify the trait to exclude the last `void*` member of the `S.tuple`. Given that it's always added as the last member. Also note that pragma(msg, __traits(isDisabled, S.this(this))); fails to compile a

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-09 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 14:20:41 UTC, Per Nordlöw wrote: If so, we can temporarily modify the trait to exclude the last `void*` member of the `S.tuple`. Given that it's always added as the last member. Note that `std.traits.isCopyable!S` cannot be used, because it will return true when `S

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-09 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 14:07:37 UTC, Per Nordlöw wrote: This prevents the trait `mustAddGCRangeOfStructOrUnion` [1] from detecting when a container with manual memory management doesn't have to be scanned by the GC as in, for instance, enum NoGc; struct S { @disable th

Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-09 Thread Per Nordlöw via Digitalmars-d-learn
Why (on earth) does struct S { @disable this(this); int* _ptr; } pragma(msg, typeof(S.tupleof)); prints (int*, void*) when struct S { int* _ptr; } pragma(msg, typeof(S.tupleof)); prints (int*) ?!!! This prevents the trait `mustAddGCR

Pure double to string conversion

2018-05-01 Thread Per Nordlöw via Digitalmars-d-learn
Is there a way to convert a `double` to a `string` in a `pure` function? I tried @safe pure unittest { import std.conv : to; const y = 3.14.to!string; } but it fails to compile as `pure` function `foo.__unittest_L1_C12` cannot call impure function `std.conv.to!string.to!double.to`

Re: Purity of delegate-style toString

2018-05-01 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 1 May 2018 at 12:03:15 UTC, ag0aep6g wrote: By the way, you shouldn't mark toString as @trusted when `sink` is @system. Thanks

Purity of delegate-style toString

2018-05-01 Thread Per Nordlöw via Digitalmars-d-learn
In which cases (if any) is it possible to make a delegate-style implementation of toString such as void toString(scope void delegate(const(char)[]) sink) const @trusted pure { // sink("..."); // sink.formattedWrite!"..."(...); } pure?

bitfields comparison in opEquals

2018-04-26 Thread Per Nordlöw via Digitalmars-d-learn
I have a struct with a mixin(bitfields) containing many small bitfields. I also have a class member in the struct. And because I want the class member to compare by using `is` I need to define bool opEquals(const scope typeof(this) that) const @safe pure nothrow @nogc { retu

Re: Warning on self assignment

2018-04-24 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 02:23:04 UTC, Mike Franklin wrote: Are people using self assignment of structs as a way of force-running the postblit? Is there a valid use case for that? Mike If they are, there should be a better way of force-running the postblit.

Re: Range length property

2018-04-10 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 20:16:18 UTC, Steven Schveighoffer wrote: e.g. std.array.array is going to pre-allocate an array of the correct length and fill it in, vs. appending each element as it gets them from the range. Personally, I would store the length because typically a container ran

Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-09 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 9 April 2018 at 13:51:47 UTC, Steven Schveighoffer wrote: Well, you know the type, because make returned it no? The contract is, you call obj = make!X(args), then you have to call dispose(obj), where obj is of the type X. That's how it knows. If you are thinking you want to destroy

Source expression passed to a lazy parameter

2018-04-09 Thread Per Nordlöw via Digitalmars-d-learn
Is it possible to get the source expression sent to a lazy function? So that I can implement something like show(Arg)(lazy Arg arg) { writeln(arg.sourceof, arg); } used as show(1+2+3); will print 1+2+3:6

Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-07 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 7 April 2018 at 07:50:37 UTC, Eduard Staniloiu wrote: On Friday, 6 April 2018 at 21:49:37 UTC, Per Nordlöw wrote: On Tuesday, 3 April 2018 at 09:14:28 UTC, Eduard Staniloiu wrote: So, say `reg` is your allocator, your workflow would be auto obj = reg.make!Type(args); /* do stuff *

Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-06 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 09:14:28 UTC, Eduard Staniloiu wrote: So, say `reg` is your allocator, your workflow would be auto obj = reg.make!Type(args); /* do stuff */ reg.dispose(obj); // If Type has a __dtor, it will call obj.__dtor // and then reg.deallocate(obj) If I d

Making emplaceRef public

2018-04-06 Thread Per Nordlöw via Digitalmars-d-learn
Why isn't `std.conv.emplaceRef` public when `std.conv.emplace` is? AFAICT, emplaceRef(x, ...) is a bit more @safe than emplace(&x, ...) ...

Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-02 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 2 April 2018 at 20:43:01 UTC, Alexandru Jercaianu wrote: I am not completely sure how to solve this, but maybe we can find some clues here [1]. It seems like we should use addRoot on the buffer returned by GC.instance.allocate to keep it alive. Then, we can use addRange on each node a

Re: Fast GC allocation of many small objects

2018-04-02 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 2 April 2018 at 18:22:43 UTC, Steven Schveighoffer wrote: You may be interested in this proposal, which was inspired by trying to implement a reserve feature for AAs (requires a similar mechanism). https://issues.dlang.org/show_bug.cgi?id=17881 Ok, thanks. I'll push for it. One

How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-02 Thread Per Nordlöw via Digitalmars-d-learn
As a follow-up to https://forum.dlang.org/post/jfgpngdudtprzznrc...@forum.dlang.org I managed to put together the benchmark https://github.com/nordlow/phobos-next/blob/fa3526b15c746bda50a195f4e492ab2de9c15287/benchmarks/allocators/source/app.d which run (via ldc) dub run --build=release-nobou

Re: Fast GC allocation of many small objects

2018-04-01 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 1 April 2018 at 10:59:55 UTC, Alexandru jercaianu wrote: On Saturday, 31 March 2018 at 20:17:26 UTC, Per Nordlöw wrote: On Friday, 30 March 2018 at 23:09:33 UTC, Alexandru Jercaianu wrote: Hello, You can try the following: struct Node { char[64] arr; } enum

Re: Fast GC allocation of many small objects

2018-03-31 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 31 March 2018 at 20:17:26 UTC, Per Nordlöw wrote: auto reg = Region!(NullAllocator, 16)(cast(ubyte[])buf); Thanks! Turns out that Region allocator wasn't fully qualified: https://github.com/dlang/phobos/pull/6400 This will make it possible to allocate with it in pure code

Re: Fast GC allocation of many small objects

2018-03-31 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 30 March 2018 at 23:09:33 UTC, Alexandru Jercaianu wrote: Hello, You can try the following: struct Node { char[64] arr; } enum numNodes = 100_000_000; void[] buf = GCAllocator.instance.allocate(numNodes * Node.sizeof); auto reg = Region!(NullAlloc

Re: Fast GC allocation of many small objects

2018-03-31 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 31 March 2018 at 19:31:37 UTC, Rubn wrote: Be willing to change your code, the allocator can change at any point. What you implement today may not work tomorrow, what you fix to work for tomorrow may not end up working the next day (in terms of releases). That really should be some

Re: Fast GC allocation of many small objects

2018-03-30 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 30 March 2018 at 20:38:35 UTC, rikki cattermole wrote: Use a custom allocator (that could be backed by the GC) using std.experimental.allocators :) https://dlang.org/phobos/std_experimental_allocator.html is massive. I guess I should allocate my nodes using auto node = theAllo

Fast GC allocation of many small objects

2018-03-30 Thread Per Nordlöw via Digitalmars-d-learn
I'm working on a graph database with tens of millions of small nodes containing typically around 8-64 bytes of member data. Is there a faster way of allocating many small class objects such as class Node { // abstract members } class StrNode : Node { string value; } // more Node-types

Re: Checking if a structs .init value is zero bits only

2018-03-28 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 01:39:40 UTC, Seb wrote: Have a look at: https://github.com/dlang/phobos/pull/6024 (review/feedbackon this PR is welcome!) Exactly what I wanted. Thanks! In use here https://github.com/nordlow/phobos-next/blob/41b9e0dcfbb4eed6b2ee52d0465425556f14c00f/src/open_

Re: Checking if a structs .init value is zero bits only

2018-03-28 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 00:50:31 UTC, Ali Çehreli wrote: On 03/27/2018 05:15 PM, Per Nordlöw wrote: Is there a way to check if a struct `S` can be initialized using zero bits only, so that we can allocate and initialize an array of `S` in one go using `calloc`? If not, what should such

Checking if a structs .init value is zero bits only

2018-03-27 Thread Per Nordlöw via Digitalmars-d-learn
Is there a way to check if a struct `S` can be initialized using zero bits only, so that we can allocate and initialize an array of `S` in one go using `calloc`? If not, what should such a trait look like?

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-27 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 22:00:42 UTC, Johan Engelen wrote: Indeed. Please try to manually link first (without dub) by modifying the command on which dub errors: ``` ldmd2 -flto=thin -of.dub/build/application-release-nobounds-lto-linux.posix-x86_64-ldc_2078-F2904BE3C4DA237C077E5C2B0B23442

Re: Checking @nogc-ness of an Allocator.allocate()

2018-01-11 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 11 January 2018 at 12:24:36 UTC, Nordlöw wrote: How do I check whether an aggregate member function (call for a specific argument) is @nogc or not? I want to check whether Allocator.allocate(1) (for a any Allocator) is @nogc or not? Is https://dlang.org/phobos/std_traits.ht

Re: Class allocators

2017-11-12 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 12 November 2017 at 18:34:42 UTC, Eduard Staniloiu wrote: On Saturday, 11 November 2017 at 14:26:34 UTC, Nordlöw wrote: Have anybody used allocators to construct class instances? I might be wrong, but I think you are looking for std.experimental.allocator.make [0] [0] - https://

Re: Disabled and enabled copy constructors and .dup

2017-10-24 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 24 October 2017 at 07:56:34 UTC, Biotronic wrote: struct SuppressPostblit(T) { // Disguise T as a humble array. private ubyte[T.sizeof] _payload; ... A bit too hackish for my taste, but does the job still. Thanks.

Disabled and enabled copy constructors and .dup

2017-10-24 Thread Per Nordlöw via Digitalmars-d-learn
If I have a `struct X` (container in my case) with disabled copying (postblit) and instead a .dup property, is it somehow possible, unsafe or not, to have `X` as a member of another `struct Y` with an enabled copy constructor which calls `X.dup`?

Re: Containers and arrays with custom memory allocators

2017-10-19 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 19 October 2017 at 08:47:09 UTC, Per Nordlöw wrote: These are all very performant containers, but currently lack support for std.experimental.allocator. Support for std.experimental.allocator is planned but currently not a priority. EMSI-containers have an elegant integration and

Re: Containers and arrays with custom memory allocators

2017-10-19 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 19 October 2017 at 08:47:09 UTC, Per Nordlöw wrote: explicit via .dup member and when you want to copy or pass by should be: explicit via .dup member and when you want to _move_ from one l-value to another l-value or pass by move

Re: Containers and arrays with custom memory allocators

2017-10-19 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 19 October 2017 at 08:47:09 UTC, Per Nordlöw wrote: The file hashmap.d provides both a HashSet and HashMap implementation in one go using D's compile-time-code-branching-mechanism `static if`. Correction: I've now broken it up into - https://github.com/nordlow/phobos-next/blob/

Re: Containers and arrays with custom memory allocators

2017-10-19 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 14:14:19 UTC, Ivan wrote: Hi, I am a C/C++ programmer interested in using D as a replacement for C/C++. I do care a lot about performance and memory management, so I want to use my own (or from std.experimental) memory allocators. Are there any good tutorials o

Re: Skynet 1M Fiber microbenchmark in D

2017-10-18 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 09:01:30 UTC, Per Nordlöw wrote: Creates an actor (goroutine, whatever), which spawns 10 new actors, each of them spawns 10 more actors, etc. until one million actors are created on the final level. Then, each of them returns back its ordinal number (from 0 to 9

Re: Making template instantiations more lazy

2017-10-18 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 10:36:41 UTC, Per Nordlöw wrote: Yeah I've thought of that. I still would like to have it built-in to the compiler. Would such a change cause any serious breakage?

Re: Making template instantiations more lazy

2017-10-18 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 10:17:38 UTC, Biotronic wrote: Make them templates, that should solve the problem: struct S(T) { void foo()() { compileerror; } } Yeah I've thought of that. I still would like to have it built-in to the compiler.

Making template instantiations more lazy

2017-10-18 Thread Per Nordlöw via Digitalmars-d-learn
Are there any nearby plans to make more template instantiations (especially aggregate members) lazy in DMD? Are there any specific obstacles against doing that or has it just not been prioritized?

Skynet 1M Fiber microbenchmark in D

2017-10-18 Thread Per Nordlöw via Digitalmars-d-learn
I'm curious about Fiber/coroutine performance in D compared to other languages such as Rust. How should the following test be implemented in D? Creates an actor (goroutine, whatever), which spawns 10 new actors, each of them spawns 10 more actors, etc. until one million actors are created on

Re: When to opCall instead of opIndex and opSlice?

2017-10-02 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 2 October 2017 at 18:14:24 UTC, Jacob Carlborg wrote: On 2017-10-02 17:57, Nordlöw wrote: Is implementing opCall(size_t) for structures such as array containers that already define opIndex and opSlice deprecated? I can't find any documentation on the subject on when opCall should b

Re: extern(C) and slices

2017-09-12 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 12 September 2017 at 06:23:57 UTC, Jacob Carlborg wrote: It looks like the length needs to come first [1]. I think it would be technically possible if you flipped the parameters but you would become dependent on the ABI as well. I would recommend a wrapper instead. [1] https://dla

Re: Finding chars in strings

2017-09-05 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 5 September 2017 at 15:43:02 UTC, Per Nordlöw wrote: If a character literal has type char, always below 128, can we always search for it's first byte offset in a string without decoding the string to a range of dchars? Follow up question: If a character literal has type char, can w

Finding chars in strings

2017-09-05 Thread Per Nordlöw via Digitalmars-d-learn
If a character literal has type char, always below 128, can we always search for it's first byte offset in a string without decoding the string to a range of dchars?

Re: Parse tree node allocator

2017-09-01 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 31 August 2017 at 15:55:26 UTC, Stefan Koch wrote: On Thursday, 31 August 2017 at 15:43:05 UTC, Per Nordlöw wrote: Which allocator is best suited for allocating tree nodes (all of equal size around 40-60 bytes in size) in one shot and then delete them all in one go? My use case is

Parse tree node allocator

2017-08-31 Thread Per Nordlöw via Digitalmars-d-learn
Which allocator is best suited for allocating tree nodes (all of equal size around 40-60 bytes in size) in one shot and then delete them all in one go? My use case is parse trees.

Casting non-aliased mutable arrays to immutable in return values

2017-08-29 Thread Per Nordlöw via Digitalmars-d-learn
Is it recommended to cast an unaliased array to `immutable` after it has been initialized? The reason for asking is that I would like the following function void[] rawReadNullTerminated(string path) @safe { import std.stdio : File; auto file = File(path, `rb`); import std.array

Idiomatic FFT(W) Wrapper

2017-07-13 Thread Per Nordlöw via Digitalmars-d-learn
Have anybody constructed an idiomatic D wrapper for FFTW? http://www.fftw.org/fftw3_doc/Tutorial.html#Tutorial I'm specifically concerned about - `RefCounted`-wrapping of the C structures `fftw_complex` and `fftw_plan` - range semantics, lazy evaluation and caching of result in stream-based

Re: Atomicity of file-copying/moving

2017-05-17 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 17 May 2017 at 19:56:52 UTC, Per Nordlöw wrote: On Tuesday, 16 May 2017 at 10:57:08 UTC, FreeSlave wrote: Not sure about renaming but copying is not atomic on Posix because it does not handle interruption by signal. I opened issue about that https://issues.dlang.org/show_bug.cgi

Re: Atomicity of file-copying/moving

2017-05-17 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 16 May 2017 at 10:57:08 UTC, FreeSlave wrote: Not sure about renaming but copying is not atomic on Posix because it does not handle interruption by signal. I opened issue about that https://issues.dlang.org/show_bug.cgi?id=17296 The standard way is to copy the source to a tempora

Re: Structure of Arrays vs Array of Structures

2017-05-15 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 15 May 2017 at 07:31:25 UTC, Nordlöw wrote: On Monday, 15 May 2017 at 06:50:04 UTC, Nicholas Wilson wrote: Yes, https://maikklein.github.io/post/soa-d/ Ok, great. Thanks. I can't seem to find any Github code repo, tough. Does it exist? Here's my fixed version of soa-d that doesn'

Re: Transitive bit-packing of fields

2017-04-30 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 30 April 2017 at 13:22:49 UTC, Stefan Koch wrote: On Sunday, 30 April 2017 at 11:02:52 UTC, Nordlöw wrote: Have anybody found a way to do transitive packing of bitfields? For instance, in import std.bitmanip : bitfields; struct X { // one bit too many to fit in one byte mi

<    1   2   3   4   5   >