Re: Do static variables in class consume memory of instances?

2021-07-22 Thread Mark Lagodych via Digitalmars-d-learn

On Thursday, 22 July 2021 at 16:05:41 UTC, Adam D Ruppe wrote:

On Thursday, 22 July 2021 at 15:50:59 UTC, Mark Lagodych wrote:
Do static variables consume *any* memory in instances, perhaps 
just for pointers to the variables?


nope

Or does compiler automatically convert 
`someObject.someStaticMember` to `SomeClass.someStaticMember`?


right


Thank you! Didn't see your reply.


Re: Do static variables in class consume memory of instances?

2021-07-22 Thread Mark Lagodych via Digitalmars-d-learn

On Thursday, 22 July 2021 at 15:50:59 UTC, Mark Lagodych wrote:
Do static variables consume *any* memory in instances, perhaps 
just for pointers to the variables?


Figured it out.

Let's try:
```d
import std.stdio;

class A {
static int 
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

}

void main() {
writeln(__traits(classInstanceSize, A));
}
```

Prints: `16`
Without static: `120`
Difference: `104`, exactly `26 * int.sizeof`

So, the answer is **NO**, no memory is taken from instances.


Do static variables in class consume memory of instances?

2021-07-22 Thread Mark Lagodych via Digitalmars-d-learn
[D documentation](https://dlang.org/spec/attribute.html#static) 
says:

Static data has one instance per thread, not one per object.


Do static variables consume *any* memory in instances, perhaps 
just for pointers to the variables? Or does compiler 
automatically convert `someObject.someStaticMember` to 
`SomeClass.someStaticMember`?


Re: Can static variables in methods be local for each object?

2021-07-20 Thread Mark Lagodych via Digitalmars-d-learn

On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote:

```d
void main()
{
X x1 = new X;
X x2 = new X;

x1.x(0).writeln;
x2.x(0).writeln;

x1.x(17).writeln;
x2.x(0).writeln;
}
```


Ow, sorry, I forgot to say. It prints:
```
1234
1234
17
17
```



Can static variables in methods be local for each object?

2021-07-20 Thread Mark Lagodych via Digitalmars-d-learn

Let's say I have this code:
```d
import std.stdio;

class X {

int x(int param) {
static int myvar = 1234;

if (param == 0) return myvar;
else { myvar = param; return myvar; }
}

}

void main()
{
X x1 = new X;
X x2 = new X;

x1.x(0).writeln;
x2.x(0).writeln;

x1.x(17).writeln;
x2.x(0).writeln;
}
```

Is there a way to make myvar local to each instance of `X` 
without making it a variable of `X`? Just curious.


Re: How to update DUB online documentation?

2021-03-28 Thread Mark Lagodych via Digitalmars-d-learn

On Sunday, 28 March 2021 at 18:02:02 UTC, Adam D. Ruppe wrote:

On Sunday, 28 March 2021 at 17:59:49 UTC, Mark Lagodych wrote:
But auto-generated online documentation and online code viewer 
show an outdated version (0.0.1). How to solve that?


Click on the documentation page, then notice at the very bottom 
of the page, in small text, there's "Clear Cache". Click that 
and it will regenerate immediately.


Otherwise you can request a specific version in the url but 
this is easier.


Wow! Thank you very much! That worked!

P.S. That button is extremely hard to notice :-S


How to update DUB online documentation?

2021-03-28 Thread Mark Lagodych via Digitalmars-d-learn

I am trying to create a DUB package.

It is already registered here [ 
https://code.dlang.org/packages/fejix ]

and its repo is here [ https://github.com/MarkLagodych/Fejix/ ].

I have updated it (0.0.3 -> 0.0.4) several hours ago. "dub fetch 
fejix" fetches the last version of my code (0.0.4) as it is 
supposed. But auto-generated online documentation and online code 
viewer show an outdated version (0.0.1). How to solve that?


Re: How to update terminal output?

2021-03-28 Thread Mark Lagodych via Digitalmars-d-learn

On Sunday, 28 March 2021 at 16:45:29 UTC, dog2002 wrote:
I mean, I want to write a string without a new line. For 
example, some command line applications have progress bars.


For a single line string I use \r. But it doesn't work for a 
multiple line string - the application is just adding new lines.


See http://www.climagic.org/mirrors/VT100_Escape_Codes.html
Basically, you just need to do this:

writeln("\033[" ~ cmd);

where cmd is your VT100 command and \033 is an Escape character.

Although some (all?) of that commands do not work in the Windows 
terminal. For instance, you can change background color ONLY 
using Windows API.