Re: Garbage Collector profiling and the dynamic array reserve() function

2017-10-17 Thread Tony via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 13:27:24 UTC, Steven Schveighoffer wrote: I don't know what "allocations" represents, but reserve actually calls gc_malloc, and the others do not (the space is available to expand into the block). There should be only one allocation IMO. -Steve So there

Re: Writing some built-in functions for Bash, possible?

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 03:48:01 UTC, Ky-Anh Huynh wrote: Some examples in C are in [2]. My experience: Dlang has `pipe` support however the syntax is not as clean as Bash :) Most of the times I see short (<1k loc) Bash scripts are easy to maintain than Ruby (and now D things)

Writing some built-in functions for Bash, possible?

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I'm using Bash heavily in my systems. Things become slow and slow when I have tons of scripts :) And sometimes it's not easy to manipulate data. You may have heard of recutils [1] which has a C extension to be loaded by Bash. Is it possible to write similar things in D, for Bash? I am

Re: How to modify process environment variables

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 08:42:09 UTC, Rene Zwanenburg wrote: On Tuesday, 17 October 2017 at 05:57:50 UTC, Ky-Anh Huynh wrote: On Tuesday, 17 October 2017 at 04:56:23 UTC, ketmar wrote: you can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there.

Re: How to modify process environment variables

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 11:49:32 UTC, Jacob Carlborg wrote: On 2017-10-17 06:51, Ky-Anh Huynh wrote: Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new

Re: testing if data is allocated on the stack or heap

2017-10-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/17/17 7:32 PM, flamencofantasy wrote: On Tuesday, 17 October 2017 at 17:27:17 UTC, Biotronic wrote: On Tuesday, 17 October 2017 at 15:33:02 UTC, drug wrote: [...] I have very little knowledge about sbrk, so here's my solution. Tested on win32 and win64. [...] Try this; unittest {

Re: testing if data is allocated on the stack or heap

2017-10-17 Thread flamencofantasy via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 17:27:17 UTC, Biotronic wrote: On Tuesday, 17 October 2017 at 15:33:02 UTC, drug wrote: [...] I have very little knowledge about sbrk, so here's my solution. Tested on win32 and win64. [...] Try this; unittest { int[5*1024] n; int* p = new int;

Re: How do I determine the system version on Windows?

2017-10-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/17/17 6:04 PM, Nieto wrote: I need to determine the operating system version. From XP to win 10. How do I do that? https://msdn.microsoft.com/en-us/library/windows/desktop/ms724429(v=vs.85).aspx -Steve

How do I determine the system version on Windows?

2017-10-17 Thread Nieto via Digitalmars-d-learn
I need to determine the operating system version. From XP to win 10. How do I do that?

Re: testing if data is allocated on the stack or heap

2017-10-17 Thread user1234 via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 17:27:17 UTC, Biotronic wrote: On Tuesday, 17 October 2017 at 15:33:02 UTC, drug wrote: [...] I have very little knowledge about sbrk, so here's my solution. Tested on win32 and win64. [...] Nice solution. Is `stackStart` thread local on purpose?

Re: Temporary objects as function parameters or when-is-this-shit-going-to-end?

2017-10-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/17/17 12:27 PM, John Burton wrote: On Friday, 13 October 2017 at 10:35:56 UTC, Jack Applegame wrote: If you don't want to get the great PITA, never create temporary objects in function parameters. I recently spent a whole day digging through my reference counted containers library. But

Re: testing if data is allocated on the stack or heap

2017-10-17 Thread drug via Digitalmars-d-learn
17.10.2017 20:27, Biotronic пишет: module stackCheck; private size_t stackStart; enum size_t pageSize = 0x1000; static this() {     import core.stdc.stdlib : alloca;     stackStart = cast(size_t)alloca(size_t.sizeof) & ~(pageSize-1); } bool onStack(void* p) {     size_t end = (cast(size_t)

Re: testing if data is allocated on the stack or heap

2017-10-17 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 15:33:02 UTC, drug wrote: My code fails and I guess the reason is I have a slice to data in the stack and it becomes garbage in some moment. So I need a way to check where data is placed. Is it right that it can be done in linux using `sbrk` so that if the addr

Re: readln of german Umlaute (terminal.d) / readln)

2017-10-17 Thread Andre Pany via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 15:02:29 UTC, Adam D. Ruppe wrote: Or try this newest commit https://github.com/adamdruppe/arsd/blob/master/terminal.d and see if it works better for you. Thank you Adam. The ascii thing was causing the issue in the windows console. Now it is working fine.

Re: readln of german Umlaute (terminal.d) / readln)

2017-10-17 Thread user1234 via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 15:02:29 UTC, Adam D. Ruppe wrote: Or try this newest commit https://github.com/adamdruppe/arsd/blob/master/terminal.d and see if it works better for you. in the commit message: ~~ascii~~ ANSI.

Re: Temporary objects as function parameters or when-is-this-shit-going-to-end?

2017-10-17 Thread John Burton via Digitalmars-d-learn
On Friday, 13 October 2017 at 10:35:56 UTC, Jack Applegame wrote: If you don't want to get the great PITA, never create temporary objects in function parameters. I recently spent a whole day digging through my reference counted containers library. But nasty bug was not there, but in the

Re: readln of german Umlaute (terminal.d) / readln)

2017-10-17 Thread notna via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 15:02:29 UTC, Adam D. Ruppe wrote: Or try this newest commit https://github.com/adamdruppe/arsd/blob/master/terminal.d and see if it works better for you. - Here is what I use in one of my tools... and I never had problems with German password so far ;)

Re: Splitting a sequence using a binary predicate on adjacent elements

2017-10-17 Thread Andrea Fontana via Digitalmars-d-learn
More phobos-ized version: https://run.dlang.io/is/iwgeAl Andrea

testing if data is allocated on the stack or heap

2017-10-17 Thread drug via Digitalmars-d-learn
My code fails and I guess the reason is I have a slice to data in the stack and it becomes garbage in some moment. So I need a way to check where data is placed. Is it right that it can be done in linux using `sbrk` so that if the addr of data is less than `sbrk(0)` returning then data is on

Re: testing if data is allocated on the stack or heap

2017-10-17 Thread drug via Digitalmars-d-learn
https://run.dlang.io/is/vOh6YY

Re: readln of german Umlaute (terminal.d) / readln)

2017-10-17 Thread Adam D. Ruppe via Digitalmars-d-learn
Or try this newest commit https://github.com/adamdruppe/arsd/blob/master/terminal.d and see if it works better for you.

Re: readln of german Umlaute (terminal.d) / readln)

2017-10-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 12:08:57 UTC, Andre Pany wrote: I want to read passwords from the console (should be work on windows / linux / macos). Do you have a little test program I can copy/paste? I suspect this is because I called ReadConsoleInputA instead of W for some weird reson..

Re: Assert and undefined behavior

2017-10-17 Thread Jesse Phillips via Digitalmars-d-learn
On Saturday, 14 October 2017 at 09:32:32 UTC, Timon Gehr wrote: The compiler can easily prove that the value of data.length does not change between the two points in the program. According to the specification, the behavior of the program is undefined in case the assertion fails, not just the

Re: Containers and arrays with custom memory allocators

2017-10-17 Thread Aldo 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

Containers and arrays with custom memory allocators

2017-10-17 Thread Ivan via Digitalmars-d-learn
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 or examples about how to use custom memory allocators for

Re: Splitting a sequence using a binary predicate on adjacent elements

2017-10-17 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 13:09:18 UTC, Nordlöw wrote: I can't find any algorithm/range in Phobos that can be used to split (eagerly or lazily) a sequence using a binary predicate on adjacent elements as follows [1,2,3,5,10,11,12,13,20,21,100].splitBy!"a + 1 != b"() should evaluate to

Re: Splitting a sequence using a binary predicate on adjacent elements

2017-10-17 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 13:25:01 UTC, Nordlöw wrote: On Tuesday, 17 October 2017 at 13:09:18 UTC, Nordlöw wrote: Is there one? If not, what should we call it?...yet another overload of `splitter()` with a binary predicate and only a single parameter `Range input`? Would probably

Re: Garbage Collector profiling and the dynamic array reserve() function

2017-10-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/17/17 2:14 AM, Tony wrote: Found this unanswered question on StackOverflow. This program: import std.stdio; void add(ref int[] data) {     data ~= 1;     data ~= 2; } void main() {     int[] a;     writeln("capacity:",a.capacity);     auto cap = a.reserve(1000); // allocated may

Re: Can't use function with same name as module?

2017-10-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/17/17 2:13 AM, Shriramana Sharma wrote: Hello. fun.d: import std.stdio; void fun() { writeln("Hello"); } main.d: import fun; void main() { fun(); } $ dmd -oftest fun.d main.d main.d(2): Error: function expected before (), not module fun of type void Why can't I use a function of the

Re: Splitting a sequence using a binary predicate on adjacent elements

2017-10-17 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 13:09:18 UTC, Nordlöw wrote: Is there one? If not, what should we call it?...yet another overload of `splitter()` with a binary predicate and only a single parameter `Range input`?

Re: What is the best way to use requests and iopipe on gzipped JSON file

2017-10-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/17/17 4:33 AM, ikod wrote: Hello, Steve On Friday, 13 October 2017 at 22:22:54 UTC, Steven Schveighoffer wrote: On 10/13/17 6:18 PM, ikod wrote: On Friday, 13 October 2017 at 19:17:54 UTC, Steven Schveighoffer wrote: Eventually, something like this will be possible with jsoniopipe (I

Splitting a sequence using a binary predicate on adjacent elements

2017-10-17 Thread Nordlöw via Digitalmars-d-learn
I can't find any algorithm/range in Phobos that can be used to split (eagerly or lazily) a sequence using a binary predicate on adjacent elements as follows [1,2,3,5,10,11,12,13,20,21,100].splitBy!"a + 1 != b"() should evaluate to [[1,2,3], [5], [10,11,12,13], [20,21], [100]] . Is there

Re: Can't use function with same name as module?

2017-10-17 Thread Shriramana Sharma via Digitalmars-d-learn
Have reported https://issues.dlang.org/show_bug.cgi?id=17907

readln of german Umlaute (terminal.d) / readln)

2017-10-17 Thread Andre Pany via Digitalmars-d-learn
Hi, I want to read passwords from the console (should be work on windows / linux / macos). Adam Ruppe has a quite nice library (terminal.d) which allows to deactivating the echo to the console, which makes sense for passwords. But I do not get it working with terminal.d nor with std.stdio:

Re: How to modify process environment variables

2017-10-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-10-17 06:51, Ky-Anh Huynh wrote: Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new (sub)process is created. In C `putEnv` the answer is positive:

Re: Tango + D2 + Mac

2017-10-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-10-17 04:52, Fat_Umpalumpa wrote: I am having a lot of trouble trying to install Tango to use with D2 on my mac os Sierra. Is this even possible? Thanks! It can be used as a Dub package [1]. But it will not compile with the latest version of DMD. 2.071.0 is the latest version it

Re: Can't use function with same name as module?

2017-10-17 Thread Shriramana Sharma via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 08:26:12 UTC, Daniel Kozak wrote: You can: import fun : fun; Yes I found this but it is unnecessarily verbose. At the same time I also find that it is possible to declare a struct or class with the same name as module: str.d: struct str { int a; } strmain.d:

Re: What's the best way to programmatically detect the most recent release of DMD and others?

2017-10-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-10-16 20:32, Andrew Edwards wrote: You're a godsend. Thank you very much. :D -- /Jacob Carlborg

Re: debugging in vs code on Windows

2017-10-17 Thread Dmitry via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 08:38:20 UTC, Arjan wrote: Before this will work, one must install the Microsoft C/C++ Addin i.e. ms-vscode.cpptools. Start debugging and select the C++ debugger. Yep https://forum.dlang.org/post/xwsvxphjtzgwjyrgd...@forum.dlang.org

Re: debugging in vs code on Windows

2017-10-17 Thread Domain via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 08:43:33 UTC, Domain wrote: On Tuesday, 17 October 2017 at 03:10:52 UTC, Dmitry wrote: On Tuesday, 17 October 2017 at 02:32:49 UTC, Domain wrote: Can you share your tasks.json and launch.json? tasks.json - I don't have this file. launch.json: { "version":

Re: debugging in vs code on Windows

2017-10-17 Thread Domain via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 03:10:52 UTC, Dmitry wrote: On Tuesday, 17 October 2017 at 02:32:49 UTC, Domain wrote: Can you share your tasks.json and launch.json? tasks.json - I don't have this file. launch.json: { "version": "0.2.0", "configurations": [ {

Re: How to modify process environment variables

2017-10-17 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 05:57:50 UTC, Ky-Anh Huynh wrote: On Tuesday, 17 October 2017 at 04:56:23 UTC, ketmar wrote: you can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there. D is not antagonistic to C, and doesn't try to replace the whole

Re: debugging in vs code on Windows

2017-10-17 Thread Arjan via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 03:10:52 UTC, Dmitry wrote: On Tuesday, 17 October 2017 at 02:32:49 UTC, Domain wrote: Can you share your tasks.json and launch.json? tasks.json - I don't have this file. launch.json: { "version": "0.2.0", "configurations": [ {

Re: What is the best way to use requests and iopipe on gzipped JSON file

2017-10-17 Thread ikod via Digitalmars-d-learn
Hello, Steve On Friday, 13 October 2017 at 22:22:54 UTC, Steven Schveighoffer wrote: On 10/13/17 6:18 PM, ikod wrote: On Friday, 13 October 2017 at 19:17:54 UTC, Steven Schveighoffer wrote: Eventually, something like this will be possible with jsoniopipe (I need to update and release this

Re: Can't use function with same name as module?

2017-10-17 Thread Daniel Kozak via Digitalmars-d-learn
You can: import fun : fun; int main(string[] args) { fun(); return 0; } On Tue, Oct 17, 2017 at 10:08 AM, Shriramana Sharma via Digitalmars-d-learn wrote: > On Tuesday, 17 October 2017 at 07:33:15 UTC, evilrat wrote: > >> Compiler made that way so it

Re: Tango + D2 + Mac

2017-10-17 Thread crimaniak via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 04:01:54 UTC, Fat_Umpalumpa wrote: Do you by any chance know anything that replaced std.xml? Everything I look up on it suggests not to use it. Is this really a problem? In this case, I can help: I recommend to use it. And only if you really will have

Re: Can't use function with same name as module?

2017-10-17 Thread Shriramana Sharma via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 07:33:15 UTC, evilrat wrote: Compiler made that way so it doesn't guess or assume too much, because later on it will bite you when you don't even expect that, and in some unpredictable place too. Can you give an example for when it will bite me? It seems very

Re: partiallyQualifiedName?

2017-10-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 06:38:52 UTC, Biotronic wrote: If I understand things correctly, you only care about enums nested in scopes up to the module scope, right? If so, this seems to fit the bill: enum A {a} struct S { enum B {b} struct S2 { enum C {c} C c;

Re: Can't use function with same name as module?

2017-10-17 Thread evilrat via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 06:13:45 UTC, Shriramana Sharma wrote: Hello. fun.d: import std.stdio; void fun() { writeln("Hello"); } main.d: import fun; void main() { fun(); } $ dmd -oftest fun.d main.d main.d(2): Error: function expected before (), not module fun of type void Why can't

Re: partiallyQualifiedName?

2017-10-17 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 16 October 2017 at 23:56:00 UTC, Nicholas Wilson wrote: using fullyQualifiedName [here] (https://github.com/libmir/dcompute/blob/master/source/dcompute/driver/ocl/util.d#L120) leads to a large compilation slowdown, but I only need it to disambiguate up to the module level i.e. so

Re: partiallyQualifiedName?

2017-10-17 Thread Biotronic via Digitalmars-d-learn
On Monday, 16 October 2017 at 23:56:00 UTC, Nicholas Wilson wrote: using fullyQualifiedName [here] (https://github.com/libmir/dcompute/blob/master/source/dcompute/driver/ocl/util.d#L120) leads to a large compilation slowdown, but I only need it to disambiguate up to the module level i.e. so

Garbage Collector profiling and the dynamic array reserve() function

2017-10-17 Thread Tony via Digitalmars-d-learn
Found this unanswered question on StackOverflow. This program: import std.stdio; void add(ref int[] data) { data ~= 1; data ~= 2; } void main() { int[] a; writeln("capacity:",a.capacity); auto cap = a.reserve(1000); // allocated may be more than requested assert(cap

Can't use function with same name as module?

2017-10-17 Thread Shriramana Sharma via Digitalmars-d-learn
Hello. fun.d: import std.stdio; void fun() { writeln("Hello"); } main.d: import fun; void main() { fun(); } $ dmd -oftest fun.d main.d main.d(2): Error: function expected before (), not module fun of type void Why can't I use a function of the same name as the module? IIUC import fun

Re: How to modify process environment variables

2017-10-17 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 04:56:23 UTC, ketmar wrote: you can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there. D is not antagonistic to C, and doesn't try to replace the whole libc with it's own libraries. so if you see something that libc has