Re: GC memory fragmentation

2021-04-11 Thread Nathan S. via Digitalmars-d-learn
On Sunday, 11 April 2021 at 09:10:22 UTC, tchaloupka wrote: Hi, we're using vibe-d (on Linux) for a long running REST API server and have problem with constantly growing memory until system kills it with OOM killer. One thing that comes to mind: is your application compiled as 32-bit? The ga

Re: How do I check if a type is assignable to null at compile time?

2021-02-25 Thread Nathan S. via Digitalmars-d-learn
On Friday, 26 February 2021 at 05:34:26 UTC, Paul Backus wrote: On Friday, 26 February 2021 at 05:25:14 UTC, Jack wrote: I started with: enum isAssignableNull(T) = is(T : Object) || isPointer(T); but how do I cover all cases? Something like this should work: enum isAssignableNull(T) = __tra

Re: How do I check if a type is assignable to null at compile time?

2021-02-25 Thread Nathan S. via Digitalmars-d-learn
On Friday, 26 February 2021 at 05:25:14 UTC, Jack wrote: I started with: enum isAssignableNull(T) = is(T : Object) || isPointer(T); but how do I cover all cases? If I understand what you mean by "is assignable to null", this should do it: --- enum bool isAssignableNull(T) = is(typeof(null)

Re: Is this a compiler error? "recursive template expansion"

2020-12-08 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 8 December 2020 at 22:01:52 UTC, Basile B. wrote: On Tuesday, 8 December 2020 at 20:11:40 UTC, Nathan S. wrote: The following code fails to compile. Is this a compiler error or if not what is wrong with the code? What is wrong is that partial specialization is not correct. The corr

Is this a compiler error? "recursive template expansion"

2020-12-08 Thread Nathan S. via Digitalmars-d-learn
The following code fails to compile. Is this a compiler error or if not what is wrong with the code? --- struct Template2(T) { // If both of the following are removed compilation succeeds // without any other changes: enum tString = T.stringof; static if (is(T == class))

Re: std.conv.ConvException from double to uint64_t, but only locally in a large project

2020-08-04 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 4 August 2020 at 17:49:56 UTC, drathier wrote: Replaced all mentions of uint64_t with ulong, and now it works. Must have an enum called uint64_t defined somewhere in a library I depend on or something? Really wish this was clearer. BTW I believe the reason that `uint64_t` is an enu

Re: Why is this allowed

2020-07-01 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 16:22:57 UTC, JN wrote: Spent some time debugging because I didn't notice it at first, essentially something like this: int[3] foo = [1, 2, 3]; foo = 5; writeln(foo); // 5, 5, 5 Why does such code compile? I don't think this should be permitted, because it's easy

Re: Distinguish between a null array and an empty array

2020-05-25 Thread Nathan S. via Digitalmars-d-learn
On Sunday, 24 May 2020 at 12:12:31 UTC, bauss wrote: Is there a way to do that? Since the following are both true: int[] a = null; int[] b = []; assert(a is null); assert(!a.length); assert(b is null); assert(!b.length); What I would like is to tell that b is an empty array and a is a null

Re: link error on Windows

2020-05-20 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 19 May 2020 at 04:54:38 UTC, Joel wrote: I tried with DMD32 D Compiler v2.088.1-dirty, and it compiled and created an exe file, but not run (msvcr100.dll not found - and tried to find it on the net without success). DMD 2.089 changed the default linking options. I bet an up-to-dat

Re: AA code 50x slower

2020-02-16 Thread Nathan S. via Digitalmars-d-learn
On Sunday, 16 February 2020 at 12:57:43 UTC, AlphaPurned wrote: template AA(string[] S) { auto _do() { int[string] d; foreach(s; S) d[s] = 0; return d; } enum AA = _do; } if (t in AA!(["a", "and", "mp4", "mp3", "the", "with", "live", "no", "&", "of", "band"])) continue; Th

How to get the name of an object's class at compile time?

2020-02-16 Thread Nathan S. via Digitalmars-d-learn
What I want is something like this: string className(in Object obj) { return obj is null ? "null" : typeid(obj).name; } ...except I want it to work in CTFE. What is the way to do this in D?

Re: Is there a way to slice non-array type in @safe?

2019-07-11 Thread Nathan S. via Digitalmars-d-learn
On Thursday, 11 July 2019 at 16:31:58 UTC, Stefanos Baziotis wrote: I searched the forum but did not find something. I want to do this: int foo(T)(ref T s1, ref T s2) { const byte[] s1b = (cast(const(byte)*)&s1)[0 .. T.sizeof]; const byte[] s2b = (cast(const(byte)*)&s2)[0 .. T.sizeof];

Is there any way to define an interface that can implicitly convert to Object?

2019-07-10 Thread Nathan S. via Digitalmars-d-learn
I want to be able to do things like: --- bool isSame(Object a, Object b) { return a is b; } interface SomeInterface { int whatever(); } bool failsToCompile(SomeInterface a, SomeInterface b) { return isSame(a, b); } --- Error: function isSame(Object a, Object b) is not callable using argumen

Re: Casting to interface not allowed in @safe code?

2019-06-25 Thread Nathan S. via Digitalmars-d-learn
On Sunday, 23 June 2019 at 21:24:14 UTC, Nathan S. wrote: https://issues.dlang.org/show_bug.cgi?id=2. The fix for this has been accepted and is set for inclusion in DMD 2.080.

Re: Casting to interface not allowed in @safe code?

2019-06-23 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 07:59:13 UTC, Jim wrote: On Tuesday, 21 May 2019 at 07:33:17 UTC, rumbu wrote: On Tuesday, 21 May 2019 at 07:16:49 UTC, Jim wrote: On Tuesday, 21 May 2019 at 07:04:27 UTC, rumbu wrote: On Tuesday, 21 May 2019 at 05:51:30 UTC, Jim wrote: That's because foo is of type

Re: Function parameter type inference: is this example working as intended?

2018-09-04 Thread Nathan S. via Digitalmars-d-learn
On Wednesday, 5 September 2018 at 02:33:47 UTC, Nathan S. wrote: The below writes "uint". Is this working as intended? https://run.dlang.io/is/Dx2e7f Note that it's called not with a `ulong` literal but with a `long` literal.

Function parameter type inference: is this example working as intended?

2018-09-04 Thread Nathan S. via Digitalmars-d-learn
The below writes "uint". Is this working as intended? https://run.dlang.io/is/Dx2e7f --- import std.stdio; auto foo(T = uint)(uint x) { return T.stringof; } auto foo(T = ulong)(ulong x) { return T.stringof; } void main() { writeln(foo(10L)); } ---

Re: Is there a way to get the address of the function that would be used in Implicit Function Template Instantiation?

2018-06-27 Thread Nathan S. via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 22:39:26 UTC, Jonathan M Davis wrote: You could explicitly instantiate the function template and then take its address. Explicitly instantiating the template can result in a function that may be behaviorally identical but have a different address. https://run.dl

Is there a way to get the address of the function that would be used in Implicit Function Template Instantiation?

2018-06-27 Thread Nathan S. via Digitalmars-d-learn
Let's say there's a function template `doImpl` and `doImpl(x)` compiles thanks to IFTI. Is there any way to get the address of the function that would be called in `doImpl(x)`?

Re: template recursion

2018-06-26 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 26 June 2018 at 20:47:27 UTC, Steven Schveighoffer wrote: Naming the hook for `put` the same thing as the global function was one of the biggest mistakes in the range library. I almost think we would be better off to deprecate that and pick another hook name. If you ever do that i

Re: Nullable!T with T of class type

2018-06-26 Thread Nathan S. via Digitalmars-d-learn
On Monday, 25 June 2018 at 22:58:41 UTC, Jonathan M Davis wrote: Java does try to force you to initialize stuff (resulting in annoying false positives at times), but in general, it still can't guarantee when a variable is null or not and is forced to insert runtime null checks. Java can be so

Re: Nullable!T with T of class type

2018-06-26 Thread Nathan S. via Digitalmars-d-learn
On Monday, 25 June 2018 at 19:40:30 UTC, kdevel wrote: Is it possible to "lower" the Nullable operations if T is a class type such that there is only one level of nullification? Yes: https://run.dlang.io/is/hPxbyf template Nullable(S) { import std.traits : isPointer, isDynamicArray;

Re: Delegates and classes for custom code.

2018-04-16 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 17 April 2018 at 04:09:57 UTC, Chris Katko wrote: I'm having trouble conceptualizing this issue at the moment. But it seems if I pass to the delegate my object, then I can ONLY use one class type. Can you post the code you're trying to run?

Re: how to make private class member private

2018-03-15 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 22:56:31 UTC, Jonathan M Davis wrote: The downside is that it increases the number of symbols which the program has to deal with when linking against a shared library, which can have some negative effects. - Jonathan M Davis If I understand correctly it's also re

Re: "Error: address of variable this assigned to this with longer lifetime"

2018-03-14 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 22:33:56 UTC, Jonathan M Davis wrote: And you can't get rid of it, because the object can still be moved, which would invalidate the pointer that you have referring to the static array. ... https://issues.dlang.org/show_bug.cgi?id=17448 Thanks for the info.

Re: how to make private class member private

2018-03-13 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 21:36:13 UTC, Arun Chandrasekaran wrote: On Tuesday, 13 March 2018 at 13:59:00 UTC, Steven Schveighoffer wrote: On 3/12/18 10:06 PM, psychoticRabbit wrote: [...] OK, so I agree there are drawbacks. But these can be worked around. [...] Private members still h

Re: how to make private class member private

2018-03-13 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 09:14:26 UTC, psychoticRabbit wrote: what I don't like, is that I have no way at all to protect members of my class, from things in the module, without moving that class out of that module. D wants me to completely trust the module, no matter what. That's make a l

Re: "Error: address of variable this assigned to this with longer lifetime"

2018-03-13 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 21:07:33 UTC, ag0aep6g wrote: You're storing a reference to `small` in `data`. When a SmallString is copied, that reference will still point to the original `small`. When the original goes out of scope, the reference becomes invalid, a dangling pointer. Can't have t

"Error: address of variable this assigned to this with longer lifetime"

2018-03-13 Thread Nathan S. via Digitalmars-d-learn
What is this malarky? https://run.dlang.io/is/S42EBb "onlineapp.d(16): Error: address of variable this assigned to this with longer lifetime" ```d import std.stdio; struct SmallString { char[24] small; char[] data; @disable this(); this(scope const(char)[] s) @safe {

Re: Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2

2018-02-27 Thread Nathan S. via Digitalmars-d-learn
Cross-posting from the github issue (https://github.com/libmir/mir-random/issues/77) with a workaround (execute it at https://run.dlang.io/is/Swr1xU): I am not sure what the correct interface should be for this in the long run, but for now you can use a wrapper function to convert an ndv

Re: Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2

2018-02-27 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 16:42:00 UTC, Nathan S. wrote: On Tuesday, 27 February 2018 at 15:08:42 UTC, jmh530 wrote: Nevertheless, it probably can't hurt to file an issue if you can't get something like the first one to work. I would think it should just work. The problem is that `mir.r

Re: Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2

2018-02-27 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 15:08:42 UTC, jmh530 wrote: Nevertheless, it probably can't hurt to file an issue if you can't get something like the first one to work. I would think it should just work. The problem is that `mir.random.ndvariable` doesn't satisfy `mir.random.variable.isRandom

Re: std.traits.isBoolean

2018-02-19 Thread Nathan S. via Digitalmars-d-learn
On Monday, 19 February 2018 at 15:12:15 UTC, Tony wrote: But, assuming there is a use case for it, what if you want to restrict to a type that is either boolean, or a struct/class that can substitute for boolean - how do you do that without using the "private" TypeOfBoolean thing? In that ca

Re: Size threshold replace complex probing with linear search for small hash tables

2018-02-19 Thread Nathan S. via Digitalmars-d-learn
On Monday, 19 February 2018 at 10:22:12 UTC, Nordlöw wrote: I'm currently developing a combined HashMap and HashSet with open addressing You might want to consider using Robin Hood hashing to reduce the worst-case length of collision chains, regardless of what kind of probing scheme you use.

Re: opCast cannot implicitly convert a.opCast of type X to Y

2018-02-13 Thread Nathan S. via Digitalmars-d-learn
On Monday, 12 February 2018 at 02:05:16 UTC, aliak wrote: struct B(T) { T t; } struct A(T) { T t; auto opCast(U)() { return B!U(cast(U)t); } } void main() { auto a = A!int(3); auto b = cast(float)a; // error } Having the result of "cast(float) a" not be a float

Re: What does "(this This)" mean in member function templates?

2018-02-12 Thread Nathan S. via Digitalmars-d-learn
On Monday, 12 February 2018 at 08:42:42 UTC, rikki cattermole wrote: https://dlang.org/spec/template.html#TemplateThisParameter Cheers.

What does "(this This)" mean in member function templates?

2018-02-12 Thread Nathan S. via Digitalmars-d-learn
For example in std.container.rbtree: --- auto equalRange(this This)(Elem e) { auto beg = _firstGreaterEqual(e); alias RangeType = RBRange!(typeof(beg)); if (beg is _end || _less(e, beg.value)) // no values are equal return RangeType(beg, beg

Re: new int[]

2018-01-10 Thread Nathan S. via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 22:46:30 UTC, ag0aep6g wrote: If I understand correctly, the goal is to have the `int[]` itself on the GC heap. The code void main(string[] args) @nogc { int[] x = [1, 2, 3]; } won't compile, because "array literal in @nogc function 'D main' may

Re: new int[]

2018-01-10 Thread Nathan S. via Digitalmars-d-learn
Is there any problem with: import std.stdio; void main(string[] args) { int[] x = [1, 2, 3]; writeln(x); } https://run.dlang.io/is/CliWcz

Re: Does LDC support profiling at all?

2017-12-22 Thread Nathan S. via Digitalmars-d-learn
On Friday, 22 December 2017 at 09:52:26 UTC, Chris Katko wrote: DMD can use -profile and -profile=gc. But I tried for HOURS to find the equivalent for LDC and came up with only profile-guided optimization--which I don't believe I want. Yet, if we can get PGO... where's the PROFILE itself it's u

Re: why ushort alias casted to int?

2017-12-22 Thread Nathan S. via Digitalmars-d-learn
On Friday, 22 December 2017 at 10:42:28 UTC, crimaniak wrote: Hm, really. ok, I will use the explicit cast, but I don't like it. It's because the C programming language has similar integer promotion rules. That doesn't make it any more convenient if you weren't expecting it but that is the re

Re: How to catch line number of exception without catching it ?

2017-12-13 Thread Nathan S. via Digitalmars-d-learn
On Wednesday, 13 December 2017 at 18:24:09 UTC, Thomas wrote: So my question is: Is there a way to catch that line where the exception has happened without a catch ? Yes: use a debugger.

Re: Static array as immutable

2017-12-12 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 12 December 2017 at 11:37:40 UTC, Jonathan M Davis wrote: On Tuesday, December 12, 2017 10:35:15 Ivan Trombley via Digitalmars-d-learn wrote: On Tuesday, 12 December 2017 at 09:48:09 UTC, Jonathan M Davis wrote: > On Tuesday, December 12, 2017 07:33:47 Ivan Trombley via > > Digitalm

Re: minElement on array of const objects

2017-11-13 Thread Nathan S. via Digitalmars-d-learn
Unqual!Element seed = r.front; alias MapType = Unqual!(typeof(mapFun(CommonElement.init))); This looks like a job for std.typecons.Rebindable!(const A) instead of Unqual!(const A) which is used currently. I am surprised that this is the first time anyone has run into this.

Re: How to use containers in lock based concurrency

2017-11-03 Thread Nathan S. via Digitalmars-d-learn
Is this advice from 2015 outdated? I found it while I was wrestling with shared data structures, and after reading I stopped doing that. https://p0nce.github.io/d-idioms/#The-truth-about-shared The truth about shared It's unclear when and how shared will be implemented. Virtually noone use sh

Re: private keyword dont appear to do anything

2017-11-03 Thread Nathan S. via Digitalmars-d-learn
On Friday, 3 November 2017 at 20:01:27 UTC, Jonathan M Davis wrote: Most folks are surprised by this behavior I found it surprising at first but now any other way seems absurd to me. None of the benefits of data encapsulation apply to code written five lines away in the same file.

Re: Is there further documentation of core.atomic.MemoryOrder?

2017-10-03 Thread Nathan S. via Digitalmars-d-learn
Thank you. For anyone else with the same question, I also found this page helpful: http://en.cppreference.com/w/cpp/atomic/memory_order

Is there further documentation of core.atomic.MemoryOrder?

2017-09-13 Thread Nathan S. via Digitalmars-d-learn
Is there a formal description of "hoist-load", "hoist-store", "sink-load", and "sink-store" as used in core.atomic.MemoryOrder (https://dlang.org/library/core/atomic/memory_order.html)?