Re: Structure initializer VS lambda function

2023-02-19 Thread realhet via Digitalmars-d-learn

Hi again and thanks for the suggestions.

I ended up checking every {} block with the following program:
It works on a string where all the nested blocks are reduced to a 
single symbol. For example: '{', '"', '['

And all the comments and whitespaces are reduced to ' ' space.

```
enum CurlyBlockKind { empty, declarationsOrStatements, list }

auto detectCurlyBlock(CodeColumn col_)
{
auto p = col_.extractThisLevelDString.text;
p = p.replace("\n", " ");
p = p.replace("  ", " ");
p = p.replace(" {", "{");
p = p.replace(" [", "]");
p = p.replace(" (", ")");
//opt: these replaces are slow.
p = p.strip;

//first start with easy decisions at the end of the block
if(p=="") return CurlyBlockKind.empty;
if(p.endsWith(';') || p.endsWith(':')) return 
CurlyBlockKind.declarationsOrStatements;


if(p.canFind("{,") || p.canFind(",{")) return 
CurlyBlockKind.list;
if(p.canFind(';')||p.canFind('{')) return 
CurlyBlockKind.declarationsOrStatements;


//give it up: it's not a declaration, neither a statement 
block

return CurlyBlockKind.list;
}
```

Since 2.5 months I didn't changed it, and I use it every day, so 
it seems ok.


The only unsure thing in this detector is the empty block. That 
would require to check what's around the empty block, but I just 
decided to represent it with it's own category: "empty".


The recursive detection of all D statements and declarations 
become easy:
- declarationsOrStatements -> Go inside this block and detect all 
the statements and declarations.
- list -> Discover the nested blocks inside this block, but don't 
treat this block as declarations or statements, this is a list!

- empty -> do nothing


Transform static immutable string array to tuple.

2023-02-19 Thread realhet via Digitalmars-d-learn

Hello,

Is there a better way to transform a string array to a tuple or 
to an AliasSeq?


```
mixin(customSyntaxPrefixes.format!`tuple(%(%s,%))`)
```

I'd like to use this as variable length arguments passed to the 
startsWith() std function (as multiple needles).




Re: Transform static immutable string array to tuple.

2023-02-19 Thread ag0aep6g via Digitalmars-d-learn

On Sunday, 19 February 2023 at 11:08:34 UTC, realhet wrote:
Is there a better way to transform a string array to a tuple or 
to an AliasSeq?


```
mixin(customSyntaxPrefixes.format!`tuple(%(%s,%))`)
```


https://dlang.org/phobos/std_meta.html#aliasSeqOf


Re: Transform static immutable string array to tuple.

2023-02-19 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Feb 19, 2023 at 11:08:34AM +, realhet via Digitalmars-d-learn wrote:
> Hello,
> 
> Is there a better way to transform a string array to a tuple or to an
> AliasSeq?
> 
> ```
> mixin(customSyntaxPrefixes.format!`tuple(%(%s,%))`)
> ```
> 
> I'd like to use this as variable length arguments passed to the
> startsWith() std function (as multiple needles).

In situations like this it's often better to define your dats as an
AliasSeq to begin with, since it's easier to covert that to an array
than the other way round.


T

-- 
I don't trust computers, I've spent too long programming to think that they can 
get anything right. -- James Miller


Re: Transform static immutable string array to tuple.

2023-02-19 Thread realhet via Digitalmars-d-learn

Awesome, Thank both of you!

```
enum a = ["A", "B"];
writeln(a);
writeln(aliasSeqOf!a);
writeln([aliasSeqOf!a]);
```


Re: Debugging memory leaks

2023-02-19 Thread Guillaume Piolat via Digitalmars-d-learn

On Wednesday, 15 February 2023 at 18:21:34 UTC, Hipreme wrote:
I want to know if there is some way to debug memory leaks in 
runtime.


I have been dealing with that by using a profiler and checking 
D runtime function calls. Usually those which allocates has 
high cpu usage so it can be easy for those bigger ones. While 
for the smaller ones, this approach doesn't seem to work and 
looking into my task manager I can see it increasing the memory 
usage very slowly.


I wanted to know if there is an option to do that on RUNTIME. 
--vgc is not a good option as I don't care about allocations 
that happens on initialization code.


Hello,

As of a few years, Intel Inspector is free:
https://www.intel.com/content/www/us/en/developer/articles/tool/oneapi-standalone-components.html#inspector


Big struct/class and T.init

2023-02-19 Thread Guillaume Piolat via Digitalmars-d-learn

If my understanding is correct, the mere fact of having a:


struct S
{
char[16384] array;
}

And then using it anywhere, will necessarily lead to a S.init 
being created and linked, leading to a binary size inflation of 
16kb.

This is not a super high concern, but can inform design decisions.

Is this correct?


Re: Big struct/class and T.init

2023-02-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/19/23 1:11 PM, Guillaume Piolat wrote:

If my understanding is correct, the mere fact of having a:


     struct S
     {
     char[16384] array;
     }

And then using it anywhere, will necessarily lead to a S.init being 
created and linked, leading to a binary size inflation of 16kb.

This is not a super high concern, but can inform design decisions.

Is this correct?


Yes.

that's not the case for all-zero .init though. At least in 
`TypeInfo.initializer`, it's pointing to null with array size indicating 
the amount of zeroes to write.


Testing with run.dlang.io, switching between `char` and `int` changes 
the ASM output to show whether it's stored or not.


-Steve


Re: Big struct/class and T.init

2023-02-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/19/23 1:26 PM, Steven Schveighoffer wrote:

Testing with run.dlang.io, switching between `char` and `int` changes 
the ASM output to show whether it's stored or not.


And BTW, you can override this by assigning a zero default:

```d
struct S
{
char[16384] array = 0; // no .init storage
}
```

-Steve


Dub is not finding the dynamic link library MSVCR120.dll...

2023-02-19 Thread WhatMeWorry via Digitalmars-d-learn



and is abending with an error saying exactly this.  How do I 
specify the path to this library?  Can I use one of the 
environment variables in sc.ini, one of the Windows env 
variables, or one of the dub options?



Btw, I'm bypassing on purpose the official D installation.




Re: Big struct/class and T.init

2023-02-19 Thread Guillaume Piolat via Digitalmars-d-learn
On Sunday, 19 February 2023 at 18:29:05 UTC, Steven Schveighoffer 
wrote:

On 2/19/23 1:26 PM, Steven Schveighoffer wrote:

Testing with run.dlang.io, switching between `char` and `int` 
changes the ASM output to show whether it's stored or not.


And BTW, you can override this by assigning a zero default:

```d
struct S
{
char[16384] array = 0; // no .init storage
}
```

-Steve


TIL. Nice trick!


Lazy and GC Allocations

2023-02-19 Thread Etienne via Digitalmars-d-learn

Hello,

I'm wondering at which moment the following would make an 
allocation of the scope variables on the GC. Should I assume that 
the second parameter of enforce being lazy, we would get a 
delegate/literal that saves the current scope on the GC even if 
it's not needed? I'm asking purely for a performance perspective 
of avoiding GC allocations.


```
void main() {
 int a = 5;
 enforce(true, format("a: %d", a));
}
```

Thanks

Etienne


Re: Dub is not finding the dynamic link library MSVCR120.dll...

2023-02-19 Thread Mike Parker via Digitalmars-d-learn

On Sunday, 19 February 2023 at 21:05:33 UTC, WhatMeWorry wrote:


and is abending with an error saying exactly this.  How do I 
specify the path to this library?  Can I use one of the 
environment variables in sc.ini, one of the Windows env 
variables, or one of the dub options?


Btw, I'm bypassing on purpose the official D installation.


Any error about a missing DLL is a run-time error that's 
unrelated to dub or the compiler.


Normally, for end users, a missing MSVC runtime DLL means you 
have to install the MSVC Redistributable package. This version of 
the DLL you're missing is from MSVC 2013, so that's the version 
of the package you'd need.


However, I wonder what's causing the problem in the first place. 
Do you have Visual Studio installed, or are you using the 
out-of-the-box libraries and linker that ship with DMD?




Re: Lazy and GC Allocations

2023-02-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/19/23 7:50 PM, Etienne wrote:

Hello,

I'm wondering at which moment the following would make an allocation of 
the scope variables on the GC. Should I assume that the second parameter 
of enforce being lazy, we would get a delegate/literal that saves the 
current scope on the GC even if it's not needed? I'm asking purely for a 
performance perspective of avoiding GC allocations.


```
void main() {
  int a = 5;
  enforce(true, format("a: %d", a));
}
```


enforce takes a lazy variable, which I believe is scope by default, so 
no closure should be allocated.


Indeed, you can't really "save" the hidden delegate somewhere, so the 
calling function knows that the delgate can't escape.


-Steve


Re: Lazy and GC Allocations

2023-02-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 2/19/23 9:15 PM, Steven Schveighoffer wrote:
Indeed, you can't really "save" the hidden delegate somewhere, so the 
calling function knows that the delgate can't escape.


I stand corrected, you can save it (by taking the address of it).

And it's explicitly allowed by the spec.

But it still doesn't allocate a closure!

See Adam's bug report: https://issues.dlang.org/show_bug.cgi?id=23627

-Steve


Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-19 Thread forky via Digitalmars-d-learn

On Friday, 10 February 2023 at 07:04:31 UTC, Max Samukha wrote:


...
Having class-private doesn't preclude module-private. Dennis 
even submitted a PR implementing class-private, but it stalled 
because people couldn't agree on whether class-private should 
be "private to class" or "private to class instance".


It likely the 'disagreement' was intentional .. i.e. to stall ;-)

But in any case, it should be class private.



Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-19 Thread FeepingCreature via Digitalmars-d-learn

On Monday, 20 February 2023 at 05:21:44 UTC, forky wrote:

On Friday, 10 February 2023 at 07:04:31 UTC, Max Samukha wrote:


...
Having class-private doesn't preclude module-private. Dennis 
even submitted a PR implementing class-private, but it stalled 
because people couldn't agree on whether class-private should 
be "private to class" or "private to class instance".


It likely the 'disagreement' was intentional .. i.e. to stall 
;-)


But in any case, it should be class private.


There have now been three pages produced by three people all 
agreeing with each other.


At what point does it start being spam?


Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-19 Thread thebluepandabear via Digitalmars-d-learn

But in any case, it should be class private.


There have now been three pages produced by three people all 
agreeing with each other.


At what point does it start being spam?


Having a discussion !== spam.


Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-19 Thread Mike Parker via Digitalmars-d-learn
On Monday, 20 February 2023 at 06:26:34 UTC, FeepingCreature 
wrote:




There have now been three pages produced by three people all 
agreeing with each other.


At what point does it start being spam?


Yes, it's all just noise now. Let's end it here. Further posts in 
this thread will be deleted.