Re: Memory allocation failed in CT
Is this a 64 or 32 bit compiler? Also could you post the source code if possible? You could try "--DRT-gcopt=profile:1" druntime flag to see if the compiler is running out of memory for real
Re: Memory allocation failed in CT
On Tuesday, 9 July 2019 at 17:59:24 UTC, Max Haughton wrote: On Tuesday, 9 July 2019 at 17:48:52 UTC, Andrey wrote: Hello, I have got a problem with compile-time calulations. I have some code generator that should create some long string of code during CT and after generation I mixin it. If I run it normally - in run time - then there is no error and I get expected output - string with size ~ 3.5 MB. If I run it in CT then I recieve an error: [...] I don't understand why... The only operation in my generator is string concatination: _result ~= "some code...". Are you using the -lowmem flag? This enables the GC during compilation i.e. you might be running out of memory (CTFE is not efficient with memory during evaluation) I tried to turn on this flag but no success. The same error...
Re: Memory allocation failed in CT
On Tuesday, 9 July 2019 at 17:59:24 UTC, Max Haughton wrote: On Tuesday, 9 July 2019 at 17:48:52 UTC, Andrey wrote: I in addition wrote "buffer.reserve(10 * 1014 * 1024);" and it also doesn't help.
Re: Memory allocation failed in CT
On Tuesday, 9 July 2019 at 17:48:52 UTC, Andrey wrote: Hello, I have got a problem with compile-time calulations. I have some code generator that should create some long string of code during CT and after generation I mixin it. If I run it normally - in run time - then there is no error and I get expected output - string with size ~ 3.5 MB. If I run it in CT then I recieve an error: [...] I don't understand why... The only operation in my generator is string concatination: _result ~= "some code...". Are you using the -lowmem flag? This enables the GC during compilation i.e. you might be running out of memory (CTFE is not efficient with memory during evaluation)
Memory allocation failed in CT
Hello, I have got a problem with compile-time calulations. I have some code generator that should create some long string of code during CT and after generation I mixin it. If I run it normally - in run time - then there is no error and I get expected output - string with size ~ 3.5 MB. If I run it in CT then I recieve an error: core.exception.OutOfMemoryError@core\exception.d(702): Memory allocation failed 0x7FF65A80BE73 0x7FF65A80BE73 0x7FF65A80BB46 0x7FF65A7FBA5C 0x7FF65A8035EC 0x7FF65A804311 0x7FF658BA733E 0x7FF658CC561F 0x7FF658CC0CD8 0x7FF658CB3728 0x7FF658CB3826 0x7FF658CB4762 0x7FF658CB3826 0x7FF658CB3CD0 E:\Programs\LDC2\bin\ldc2.exe failed with exit code 1. I don't understand why... The only operation in my generator is string concatination: _result ~= "some code...".
Re: Is there something like a consuming take?
Hurray, it works! :-) https://run.dlang.io/is/2GMq34 I have to use classes to avoid copying when arguments are passed to a function. (And yes, there should of course be much more checks, especially when there are to few elements in the original range. And it could be speed improved and so on... I wanted to keep it simple.)
Re: Using output-range overloads of SysTime.toISO{Ext}String with formatting code
On Tuesday, 9 July 2019 at 08:51:59 UTC, Mitacha wrote: I've managed to make it work using 'alias this' and wrapper struct. https://run.dlang.io/is/3SMEFZ It's not an elegant solution, there could be a better way to do this. Yea, a wrapper struct with custom `toString` seems the most obvious way forward. No need to bother with `alias this`, though, since one only needs the wrapper struct at the point where one wants to format the datetime info. A wrapper struct like this: struct ISOExtSysTime { private SysTime systime; public void toString (Output) (ref Output output) if (isOutputRange!(Output, char)) { this.systime.toISOExtString(output); } } allows easy usage along the lines of: writefln!"%s"(ISOExtSysTime(sys_time)); ... and one could easily write a small factory function to shorten the code if needed.
Re: Using output-range overloads of SysTime.toISO{Ext}String with formatting code
On Monday, 8 July 2019 at 12:53:18 UTC, Digital Mars wrote: I guess that there is no way to have `writeln` automatically use the output range overload instead of allocating one. You need somehow to provide the output range to `toISOExtString` explicitly because `writeln` outputs the return of `toISOExtString` and have no ability to use specific overload. That is compiler calls `toISOExtString` and then passes its return to `writeln`. Probably library solution isn't possible in this case. Workaround is using own wrapper to provide output range to `toISOExtString`. This is pretty much what I'd concluded myself, but I wanted to check to make sure there wasn't some clever option I didn't know about. A helper function with wrapper struct seems the obvious way forward.
Re: SendMessageTimeoutW requires casting string to uint?
On Tuesday, 9 July 2019 at 13:10:57 UTC, a11e99z wrote: On Tuesday, 9 July 2019 at 12:14:38 UTC, BoQsc wrote: On Tuesday, 9 July 2019 at 11:11:53 UTC, Dejan Lekic wrote: auto result = SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, envi.toUTF16z, SMTO_ABORTIFHUNG, timeout, null ); C:\Users\User\Desktop>rdmd ref.d ref.d(19): Error: function `core.sys.windows.winuser.SendMessageTimeoutW(void*, uint, uint, int, uint, uint, uint*)` is not callable using argument types `(void*, int, int, const(wchar)*, int, uint, typeof(null))` ref.d(19):cannot pass argument `toUTF16z(cast(const(char)[])envi)` of type `const(wchar)*` to parameter `int` Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", "-o-", "ref.d", "-I."] // add cast to LPARAM for SendMessageTimeoutW cast( LPARAM )envi.toUTF16z, // import lib too somewhere out of main() or in command line version(Windows) pragma(lib, "user32.lib"); You are absolutely right. Here is a working example code on how to broadcast environment variables changes from D language to Windows XP, 7, 8, 10 systems, if anyone searches for it. To launch the code: rdmd broadcastSignal.d broadcastSignal.d import std.utf; version(Windows) pragma(lib, "user32.lib"); import core.sys.windows.windows : SendMessageTimeoutW; import core.sys.windows.windows : GetLastError; import core.sys.windows.windows : ERROR_SUCCESS; import core.sys.windows.windows : SMTO_ABORTIFHUNG; import core.sys.windows.windows : LPARAM; import core.sys.windows.windows : HWND_BROADCAST; import core.sys.windows.windows : WM_SETTINGCHANGE; void main(){ broadcastSettingChange(); } /** Broadcasts a signal to update All Environment variables On Windows XP, 7, 8, 10 systems. Mostly used update changes to Path environment variable. After broadcast of this signal, reopen applications, for changes to be visible. Date: 07/09/2019 License: use freely for any purpose Params: addressBroadcast = "Policy" When the system sends this message as a result of a change in policy settings, this parameter points to this string. "intl"When the system sends this message as a result of a change in locale settings, this parameter points to this string. "Environment" To effect a change in the environment variables for the system or the user, broadcast this message with lParam set to this string Returns: does not return See_Also: https://docs.microsoft.com/lt-lt/windows/win32/api/winuser/nf-winuser-sendmessagetimeouta https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange */ void broadcastSettingChange (string addressBroadcast="Environment", uint timeout=1) { void* hWnd = HWND_BROADCAST; uint Msg = WM_SETTINGCHANGE; uint wParam = 0; int lParam = cast( LPARAM )addressBroadcast.toUTF16z; uint fuFlags = SMTO_ABORTIFHUNG; uint uTimeout = timeout; uint* lpdwResult = null; int result = SendMessageTimeoutW( hWnd, Msg, wParam, lParam, SMTO_ABORTIFHUNG, uTimeout, lpdwResult ); if(result == 0) { auto errCode = GetLastError(); } }
LDC won't find ld linker -why?
I just downloaded ldc 1.15.0 for Linux from GH releases. Testing it, it will make the object file out of a hello world application, but then complain: ``` collect2: fatal error: cannot find ‘ld’ compilation terminated. ``` This is strange, because running either `ld` or `clang` (yes, I checked readme file) in the same directory as the compilation will indicate that I have both of them. And clang is version 8, same as the llvm version that 1.15.0 is based on. dmd works correctly, but downloaded that as `.rpm`. If it makes any difference, I just dumped the contents of the ldc download folder directly into my home, so that there is `~/bin/ldc2`, `~/etc/ldc2.conf`, and so on. Making a symlink to ld into ~/bin won't make a difference, and `ln` won't let me to make a hard link, it complains about something like invalid link between devices (ln is in `usr/bin/` which should be on same drive and partition as `~/bin`). What could be wrong?
Re: LDC won't find ld linker -why?
On Tuesday, 9 July 2019 at 15:25:17 UTC, Dukc wrote: (ln is in `usr/bin/` meant that `ld` is there
Re: Is there something like a consuming take?
On Sunday, 7 July 2019 at 21:55:17 UTC, Jonathan M Davis wrote: Having one range know about the other isn't enough. That just means that the take range would tell the other range that it had popped an element off, and then the other would know that it had to pop an element off. That still involves popping the same element on different ranges twice. Sounds like you didn't understand what I meant. So I tried to implement what I had in mind and I have to confess, that there is something about ranges that I do not understand yet: import std.stdio; import std.array; void main() { auto a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; call(a,5); } void call(T)(ref T range, int c) { struct Take { T* take_range; int count; @property bool empty=false; @property auto front() { return (*take_range).front; } void popFront() { (*take_range).popFront(); if (--count<=0) empty=true; } T* get_range() { assert(count==0); while (!empty) popFront(); return take_range; } } auto take = Take(,c); //writeln(take); while (!take.empty) { write(take.front); take.popFront(); } auto original_range = take.get_range(); writeln(*original_range); } Running this program leads to 12345[6, 7, 8, 9, 10, 11, 12, 13, 14, 15] as expected. But when I replace that loop at the bottom by writeln(take) the assertion in get_range fails (count==5). As all the functions are called in the same order by both the loop and writeln, I confess, that writeln somehow manages to use a copy of "take" although this isn't a ForwardRange and copying should therefore not be possible. You can try mucking around with your own implemention of take if you want, but I'd suggest that you're just better off taking the approach that it's expected that if you use take, I't not about improving or doing things different. It's just about me understanding, what happens.
Re: Why does `static foreach` lead to something calling `~=` internally?
On Sunday, 7 July 2019 at 18:45:14 UTC, 0xEAB wrote: On Sunday, 7 July 2019 at 16:51:57 UTC, 0xEAB wrote: Why does this `static foreach` lead to hidden usage of operator Further notes by Dan (aka "Wild"): I added some small printfs to the compiler, http://ix.io/1NWM It seems like it lowers it into something weird Static foreach needs a tuple. When you have a range like "0 .. 10" it has to convert that to a tuple. It does this by generating some code and running it at CTFE. Guess this was done as it was a lot simpler to do, you don't have to worry about recreating ranges as that's already done by using CTFE. What it ends up lowering to: https://github.com/dlang/dmd/blob/v2.087.0/src/dmd/cond.d#L274 * static foreach (x; { * typeof({ * foreach (x; range) return x; * }())[] __res; * foreach (x; range) __res ~= x; * return __res; * }()) { ... }
Re: SendMessageTimeoutW requires casting string to uint?
On Tuesday, 9 July 2019 at 12:14:38 UTC, BoQsc wrote: On Tuesday, 9 July 2019 at 11:11:53 UTC, Dejan Lekic wrote: auto result = SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, envi.toUTF16z, SMTO_ABORTIFHUNG, timeout, null ); C:\Users\User\Desktop>rdmd ref.d ref.d(19): Error: function `core.sys.windows.winuser.SendMessageTimeoutW(void*, uint, uint, int, uint, uint, uint*)` is not callable using argument types `(void*, int, int, const(wchar)*, int, uint, typeof(null))` ref.d(19):cannot pass argument `toUTF16z(cast(const(char)[])envi)` of type `const(wchar)*` to parameter `int` Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", "-o-", "ref.d", "-I."] // add cast to LPARAM for SendMessageTimeoutW cast( LPARAM )envi.toUTF16z, // import lib too somewhere out of main() or in command line version(Windows) pragma(lib, "user32.lib");
Re: SendMessageTimeoutW requires casting string to uint?
On Tuesday, 9 July 2019 at 11:11:53 UTC, Dejan Lekic wrote: Now that I browsed the std.utf more, I realised what fits your need best is the https://dlang.org/phobos/std_utf.html#toUTF16z So far, this is what I have: Filename: myVersion.d import core.sys.windows.windows : SendMessageTimeoutW; import core.sys.windows.windows : GetLastError; import core.sys.windows.windows : ERROR_SUCCESS; import core.sys.windows.windows : SMTO_ABORTIFHUNG; import core.sys.windows.windows : LPARAM; import core.sys.windows.windows : HWND_BROADCAST; import core.sys.windows.windows : WM_SETTINGCHANGE; import std.utf; void main(){ broadcastSettingChange(); } void broadcastSettingChange (string envi="Environment", uint timeout=1) { auto result = SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, envi.toUTF16z, SMTO_ABORTIFHUNG, timeout, null ); if(result == 0) { auto errCode = GetLastError(); } } The dmd output: C:\Users\User\Desktop>rdmd ref.d ref.d(19): Error: function `core.sys.windows.winuser.SendMessageTimeoutW(void*, uint, uint, int, uint, uint, uint*)` is not callable using argument types `(void*, int, int, const(wchar)*, int, uint, typeof(null))` ref.d(19):cannot pass argument `toUTF16z(cast(const(char)[])envi)` of type `const(wchar)*` to parameter `int` Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", "-o-", "ref.d", "-I."]
Blog Post #0051: MVC IV - ComboBox with Text
Today's post starts a mini series-within-a-series on dressing up the ComboBox using a ListStore. Essentially, it's ListStore basics leading up to how this type of model is used with a TreeView. You can find it here: https://gtkdcoding.com/2019/07/09/0051-mvc-iv-combobox-text.html
Re: SendMessageTimeoutW requires casting string to uint?
On Tuesday, 9 July 2019 at 10:34:54 UTC, BoQsc wrote: All I know that there was toString16z function from tango project, that made it all work. Now that I browsed the std.utf more, I realised what fits your need best is the https://dlang.org/phobos/std_utf.html#toUTF16z
Re: SendMessageTimeoutW requires casting string to uint?
On Tuesday, 9 July 2019 at 10:34:54 UTC, BoQsc wrote: I'm quite new to the programming, and I'm getting unsure how to make SendMessageTimeoutW to work with D lang. Most of my attention right now resides around the Argument of the SendMessageTimeoutW function: "Environment", It seems that SendMessageTimeoutW accepts only uint type, and string can't be directly used. I think that I have to convert string characters to "C-style 0 terminated string". And everything should work? But I'm unsure how to do that. All I know that there was toString16z function from tango project, that made it all work. std.utf module has all encoding/decoding you need (in this case UTF-16). I guess You need to convert your string using toUTF16 ( https://dlang.org/phobos/std_utf.html#toUTF16 ). I do not do Windows programming so I am not 100% sure whether this will work or not. Give it a try.
Re: SendMessageTimeoutW requires casting string to uint?
On Tuesday, 9 July 2019 at 11:06:54 UTC, Dejan Lekic wrote: std.utf module has all encoding/decoding you need (in this case UTF-16). I guess You need to convert your string using toUTF16 ( https://dlang.org/phobos/std_utf.html#toUTF16 ). I do not do Windows programming so I am not 100% sure whether this will work or not. Give it a try. Maybe even the straightforward to!wchar will work!?
SendMessageTimeoutW requires casting string to uint?
I'm quite new to the programming, and I'm getting unsure how to make SendMessageTimeoutW to work with D lang. Most of my attention right now resides around the Argument of the SendMessageTimeoutW function: "Environment", It seems that SendMessageTimeoutW accepts only uint type, and string can't be directly used. I think that I have to convert string characters to "C-style 0 terminated string". And everything should work? But I'm unsure how to do that. All I know that there was toString16z function from tango project, that made it all work. http://www.dsource.org/projects/tango/docs/stable/tango.stdc.stringz.html#toString32z cast(LPARAM)(settingName.toString16z()) Here is how the method was before my modifications: void broadcastSettingChange (string settingName, uint timeout=1) { auto result = SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, cast(LPARAM)(settingName.toString16z(), SMTO_ABORTIFHUNG, timeout, null ); And finally, here is myVersion.d that throws an error (that I use incorrect variable type for the argument) myVersion.d import core.sys.windows.windows : SendMessageTimeoutW; import core.sys.windows.windows : GetLastError; import core.sys.windows.windows : ERROR_SUCCESS; import core.sys.windows.windows : SMTO_ABORTIFHUNG; import core.sys.windows.windows : LPARAM; import core.sys.windows.windows : HWND_BROADCAST; import core.sys.windows.windows : WM_SETTINGCHANGE; void main(){ broadcastSettingChange(); } void broadcastSettingChange (uint timeout=1) { auto result = SendMessageTimeoutW( HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", SMTO_ABORTIFHUNG, timeout, null ); if(result == 0) { auto errCode = GetLastError(); } }
Re: Trying to alias this a grapheme range + making it a forward range
On Monday, 8 July 2019 at 23:01:49 UTC, ag0aep6g wrote: On 08.07.19 23:55, aliak wrote: [...] `source.front` is a temporary `Grapheme` and you're calling `opSlice` on it. The documentation for `Grapheme.opSlice` warns: "Invalidates when this Grapheme leaves the scope, attempts to use it then would lead to memory corruption." [1] Ah. Right. Thanks! [...] hah yes, I realized this as well. [...] No you're right. It was indeed just making things more complicated and was just a bad idea. [...] Cheers, - Ali
Using output-range overloads of SysTime.toISO{Ext}String with formatting code
On Monday, 8 July 2019 at 12:53:18 UTC, Digital Mars wrote: 08.07.2019 13:38, Joseph Rushton Wakeling пишет: [...] Sorry that my answer wasn't thoughtful. I guess that there is no way to have `writeln` automatically use the output range overload instead of allocating one. You need somehow to provide the output range to `toISOExtString` explicitly because `writeln` outputs the return of `toISOExtString` and have no ability to use specific overload. That is compiler calls `toISOExtString` and then passes its return to `writeln`. Probably library solution isn't possible in this case. Workaround is using own wrapper to provide output range to `toISOExtString`. I've managed to make it work using 'alias this' and wrapper struct. https://run.dlang.io/is/3SMEFZ It's not an elegant solution, there could be a better way to do this.