On Monday, 17 January 2022 at 03:11:50 UTC, Steven Schveighoffer
wrote:
The profile=gc appears to only show GC allocations that the
*compiler* initiates (i.e. via `new`, array operations (like
appending) or closure allocations). It does not detect that the
functions that actually allocate mem
On Monday, 17 January 2022 at 00:54:19 UTC, forkit wrote:
..
module test;
import std;
@safe void main()
{
// mArr1 is a dynamic array allocated on the gc heap.
int[][] mArr1 = [[1, 2], [3, 4], [5, 6], [7, 8]];
static assert(is(typeof(mArr1.array(;
alias R1 = typeof(mArr1)
On Sunday, 16 January 2022 at 23:34:41 UTC, Ali Çehreli wrote:
Definitely a -profile=gc bug. Here are the existing ones:
https://issues.dlang.org/buglist.cgi?quicksearch=profile%20gc
Ali
yeah, a bug makes more sense ... otherwise I really would have
had a slice to data that doesn't exist
On Sunday, 16 January 2022 at 23:03:49 UTC, Ali Çehreli wrote:
That's not correct. There are many range algorithms that are
lazy to defer memory allocation but array() is not one of
those. array() does eagerly allocate memory, which is it's
whole purpose:
https://dlang.org/phobos/std_arra
On Sunday, 16 January 2022 at 11:43:40 UTC, Ali Çehreli wrote:
So, in all three examples it is the same D feature, a slice,
that references data but the data is managed in different ways.
Ali
Well, it's fair to say, that 'range-based programming' is kinda
new to me.
With this statement:
On Monday, 27 December 2021 at 10:59:07 UTC, Ali Çehreli wrote:
...my DConf Online 2020 presentation here:
https://dconf.org/2020/online/#ali1
Ali
Hey, that is a really great presentation!
Many more people should watch it, and learn ;-)
On Sunday, 16 January 2022 at 04:58:21 UTC, Ali Çehreli wrote:
I have a problem with calling type[] a dynamic array because it
is a slice, which may be providing access to the elements of a
dynamic array.
Yes. A more useful way of describing [] would be to say:
"[] represents a dynamic ar
so at this link: https://dlang.org/spec/arrays.html
it indicates an array of type[] is of type 'Dynamic array'.
with that in mind, I ask, is this below a 'Dynamic array'.
If not, why not?
int[][] mArr2 = array(iota(1, 9).chunks(2).map!array.array);
On Saturday, 15 January 2022 at 03:48:41 UTC, Steven
Schveighoffer wrote:
Alternatively (with only one allocation for the int[] data):
```d
int[][] arrayOfArrays = iota(1, 16).array.chunks(5).array;
```
-Steve
All answers were helpful ;-)
But I like this one the best, because I find it both
On Saturday, 15 January 2022 at 02:41:08 UTC, Paul Backus wrote:
import std.algorithm: map;
import std.array: array;
int[][] arrayOfArrays = iota(1, 16).chunks(5).map!array.array;
oh. thanks!
also it seems I reposted the same question (didn't realise this
one got posted)
On Saturday, 15 January 2022 at 03:18:21 UTC, forkit wrote:
oops. ignore this - was a repost of another post that I thought
never got posted ;-)
I want to do the equivalent of this:
int[][] arrayOfarrays = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11,
12, 13, 14, 15]];
But getting the initialiser values using iota and chunks instead.
Any help will be appreciated.
note: to2Darray is not a valid statement ;-)
// ---
module test;
import
I want int[][] like this -> [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10],
[11, 12, 13, 14, 15]]
Any help will be appreciated.
note: to2Darray is not a valid statement ;-)
// ---
module test;
import std;
void main()
{
int[][] arrayOfarrays = iota(1, 16).chunks(5).to2Darray; //
how to convert this
On Thursday, 13 January 2022 at 20:32:40 UTC, Stanislav Blinov
wrote:
On Thursday, 13 January 2022 at 19:52:27 UTC, forkit wrote:
Any idea on how I can get a ptr (without hardcoding C style)
e.g. something like this:
immutable(string)*[] pointers = strings.filter!(x => x ==
"one").to!pointer
On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote:
Yes std.algorithm : filter.
```d
import std.stdio : writeln;
import std.algorithm : filter;
void main()@safe{
auto a = ["one", "one", "two", "one", "two", "one",
"one", "two"];
writeln(a);
writeln(a.filter
On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote:
Yes std.algorithm : filter.
```d
import std.stdio : writeln;
import std.algorithm : filter;
void main()@safe{
auto a = ["one", "one", "two", "one", "two", "one",
"one", "two"];
writeln(a);
writeln(a.filter
I am familiar with the concept of a slice in D.
However, a slice is a consecutive slice, is in not? (e.g) [4..$-1]
I would like a slice (or a view, or whatever name you wanna call
it), of particular elements within an array that may not be
consecutive. e.g. [4-7,8,10,13-16]
Consider below:
On Tuesday, 11 January 2022 at 21:50:00 UTC, Paul Backus wrote:
..
If you know a particular bit of code is memory safe, but the
compiler can't prove it, you can mark that code as @trusted.
For example:
() @trusted { pointers ~= &str; )();
This example uses an immediately-invoked function
On Tuesday, 11 January 2022 at 14:54:51 UTC, Paul Backus wrote:
..
If you compile with -preview=dip1000, the compiler will
actually keep track of which pointers point to stack memory,
and will allow your original code. But -preview=dip1000 is
still somewhat experimental, and the documentation
On Monday, 10 January 2022 at 03:21:46 UTC, Paul Backus wrote:
Taking the address of a local variable is forbidden in @safe
code. Even though str is a ref variable that points to a
heap-allocated string, it is still considered a local variable
because it is declared inside the body of a funct
On Sunday, 9 January 2022 at 21:56:05 UTC, Salih Dincer wrote:
Try the @trusted and in/out:
...
..
.
thanks for introducing me to the in/out feature of D :-)
I'll certainly look into that feature more.
But my question still remains:
//pointers ~= &str; // why is this *not* allowed in @safe
Do not understand why one line is not considered @safe, but the
other is.
//
module test;
import std;
@safe void main()
{
immutable string[] strings = ["one", "one", "two"];
immutable(string)*[] pointers = null;
foreach(size_t i, ref str; strings)
{
if(str == "on
On Tuesday, 4 January 2022 at 23:37:57 UTC, H. S. Teoh wrote:
Or the compiler would run out of memory before it gets to
optimizing away those assignments, so it would just outright
crash. I ran your code on my computer and got this:
uncaught exception
core.exception.AssertError@src/
On Tuesday, 4 January 2022 at 23:37:57 UTC, H. S. Teoh wrote:
... .. .
Which seems to confirm my suspicions.
T
yes, this sounds like it might be it.
I tried using = void;
.. results:
dmd -m64 -> just results in an 'out of memory' message (but at
least i get a message this time)
ldc2 -
strange things happen when I compile (on windows) the code below
with:
dmd -m64
(compilation just crashes - no error message at all)
or
ldc2 -m64
(compilation works, but memory usage during compilation goes
completely wild! upto 22GB, then down to 7GB, then finally
completes.)
//
mo
On Tuesday, 14 December 2021 at 08:07:43 UTC, WebFreak001 wrote:
The best way would be not doing this at all - when you
manipulate strings/arrays in D you can do so by just assigning
the elements like this:
```d
immutable(char)[] replaceChar(char[] str, char ch1, char ch2)
{
for (ulong i
On Monday, 13 December 2021 at 21:13:25 UTC, H. S. Teoh wrote:
What you should be doing is:
return to!string(str[0 .. len]);
Or just:
return str[0 .. len].idup;
T
oh.. so many different ways...(to both produce the same bug, and
also to produce the correct output).
... i
On Sunday, 12 December 2021 at 08:25:09 UTC, Dave P. wrote:
ImportC is not ready for general use yet.
I think you nailed it ;-)
https://dlang.org/changelog/2.098.1.html
On Monday, 13 December 2021 at 20:28:26 UTC, H. S. Teoh wrote:
On Mon, Dec 13, 2021 at 08:04:24PM +, forkit via
Digitalmars-d-learn wrote:
On Monday, 13 December 2021 at 12:06:53 UTC, WebFreak001 wrote:
>
> You should really use `.dup` if you want to mutate your
> string. (You w
On Monday, 13 December 2021 at 20:28:26 UTC, H. S. Teoh wrote:
On Mon, Dec 13, 2021 at 08:04:24PM +, forkit via
Digitalmars-d-learn wrote:
On Monday, 13 December 2021 at 12:06:53 UTC, WebFreak001 wrote:
>
> You should really use `.dup` if you want to mutate your
> string. (You w
On Monday, 13 December 2021 at 12:06:53 UTC, WebFreak001 wrote:
You should really use `.dup` if you want to mutate your string.
(You would need to duplicate anyway if you don't want an unsafe
cast)
(this produces an unpredictable result??)
char* w = cast(char*)str.dup;
(but this seems to wo
On Monday, 13 December 2021 at 09:49:05 UTC, forkit wrote:
char* w = cast(char*)str.toStringz; // this seems to be the
solution
class has ended ;-)
On Monday, 13 December 2021 at 09:49:05 UTC, forkit wrote:
oh...
Windows
- dmd version is 2.098.0-dirty
- ldc2 version is 1.28 (based on dmd v2.098.0)
Linux
- dmd version is 2.098
- ldc2 version is 1.20.1 (based on dmd v2.090.1)
ok. one line in this code is causing a problem (as noted in
comments)
an explanation as to the cause, is welcome ;-)
//
module test;
import std : writeln, writefln;
import std.conv : to;
void main()
{
string str = "abc;def;ab";
char* w = cast(char*)str;
w
On Saturday, 11 December 2021 at 09:25:37 UTC, Ola Fosheim
Grøstad wrote:
```putchar(…)``` is too slow!
On planet Mars maybe, but here on earth, my computer can do about
4 billion ticks per second, and my entire program (using putchar)
takes only 3084 ticks.
On Saturday, 11 December 2021 at 21:42:49 UTC, ManKey wrote:
What implementations of the C standard library does importC
support?
umm... the site has search function you know ;-)
https://dlang.org/spec/importc.html
On Saturday, 11 December 2021 at 08:05:01 UTC, Ola Fosheim
Grøstad wrote:
Using libraries can trigger hidden allocations.
ok. fine. no unnecessary, hidden allocations then.
// --
module test;
import core.stdc.stdio : putchar;
nothrow @nogc void main()
{
string str = "ab
On Friday, 10 December 2021 at 22:35:58 UTC, Arjan wrote:
"abc;def;ghi".tr(";", "", "d" );
I don't think we have enough ways of doing the same thing yet...
so here's one more..
"abc;def;ghi".substitute(";", "");
On Friday, 10 December 2021 at 12:15:18 UTC, Rumbu wrote:
I thought it's a beauty contest.
Well, if it's a beauty contest, then i got a beauty..
char[("abc;def;ab".length - count("abc;def;ab", ";"))] b =
"abc;def;ab".replace(";", "");
On Thursday, 9 December 2021 at 18:00:42 UTC, kdevel wrote:
PRO:
- saves two lines of boilerplate code
CONS:
- raw loop
- postinc ++ is only permitted in ++C
- inconsistent spacing around "="
- mixing tabs and spaces for indentation
- arrow code
more PROs:
- You become less dependent on s
On Wednesday, 8 December 2021 at 22:55:02 UTC, forkit wrote:
On Wednesday, 8 December 2021 at 22:35:35 UTC, Stanislav Blinov
wrote:
You're passing a literal. Try passing a runtime value (e.g. a
command line argument). Also, -O2 -release :) Uless, of
course, your goal is to look at debug code.
On Wednesday, 8 December 2021 at 22:35:35 UTC, Stanislav Blinov
wrote:
You're passing a literal. Try passing a runtime value (e.g. a
command line argument). Also, -O2 -release :) Uless, of course,
your goal is to look at debug code.
but this will change nothing.
the compilation cost of usin
On Wednesday, 8 December 2021 at 14:27:22 UTC, BoQsc wrote:
On Wednesday, 8 December 2021 at 14:16:16 UTC, bauss wrote:
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The string example to loop/iterate:
```
import std.st
On Sunday, 5 December 2021 at 16:24:34 UTC, Chris Katko wrote:
I know there "is" a solution, it's just so odd to have this
much difficulty using a string.
Paying attention to the online docs would help you too ;-)
https://dlang.org/library/std/socket/internet_address.this.html
But, in the e
On Monday, 29 November 2021 at 14:58:07 UTC, Willem wrote:
Thanks again for all the responses. For now -- I am simply
adding the DLL to the EXE and writing it out to the working
directory. Not elegant - but it does work.
"Programmers are not to be measured by their ingenuity and their
l
On Friday, 19 November 2021 at 17:36:55 UTC, BoQsc wrote:
Let's say I want to write a simple program that asks for an
input of a single character.
After pressing a single key on a keyboard, the character is
printed out and the program should stop.
module test;
void main()
{
import core.s
On Sunday, 14 November 2021 at 04:24:09 UTC, Stanislav Blinov
wrote:
On Sunday, 14 November 2021 at 04:05:45 UTC, forkit wrote:
However, there is no isClass method. Why not?
How do I determine if a member is a class.. I wonder...
```
static if (is(something == class)) { /* ... */ }
```
or,
On Saturday, 13 November 2021 at 23:02:15 UTC, pascal111 wrote:
I touch that D is big language, it's not small like standard C.
This will cost me much studying, so I think I need slow down
and learn it step by step.
Yes. C is so much smaller, and thus simpler (till you wanna do
something co
On Saturday, 13 November 2021 at 17:22:16 UTC, Stanislav Blinov
wrote:
On Saturday, 13 November 2021 at 08:04:56 UTC, forkit wrote:
int i;
foreach(m; __traits(allMembers, mixin(__MODULE__)))
// ...
__traits(getLocation, mixin(m))[1]);
What you really should be doing is this:
On Saturday, 13 November 2021 at 07:20:14 UTC, Ali Çehreli wrote:
It works because we mix-in the value of the string 'm', which
becomes a symbol.
('foreach' instead of 'static foreach' works as well.)
Ali
Thanks. Really appreciate the help provided in this thread :-)
Final working code be
On Saturday, 13 November 2021 at 06:05:37 UTC, Stanislav Blinov
wrote:
On Saturday, 13 November 2021 at 05:31:51 UTC, forkit wrote:
Code below is self explanatory.
Any assistance on how to get the line number is welcome ;-)
https://dlang.org/spec/traits.html#getLocation
That?
Thanks. That
Code below is self explanatory.
Any assistance on how to get the line number is welcome ;-)
// ++
module test;
import std;
class myClass{ void foo(){}}
void myFunction1(){}
void main()
{
// list the first user defined member of this module (other
than main)
On Friday, 12 November 2021 at 19:32:31 UTC, Dr Machine Code
wrote:
On Thursday, 11 November 2021 at 23:51:42 UTC, foxit wrote:
On Thursday, 11 November 2021 at 22:35:21 UTC, forkit wrote:
[...]
Actually, the reason I got soo confused is clear to me now.
I have my own GUI IDE, which I wr
On Thursday, 11 November 2021 at 19:34:42 UTC, Stanislav Blinov
wrote:
Original C code from the first post can only fail on I/O, which
is arguably out of your control. And the meat of it amounts to
10 conditional stores. Your implementations, in both C and D,
are a very, very far distance awa
On Friday, 12 November 2021 at 01:05:15 UTC, Stanislav Blinov
wrote:
On Thursday, 11 November 2021 at 22:10:04 UTC, forkit wrote:
It's called 'staged learning'.
Staged learning is the only way for humans to learn, due to
the limitations of the human cognitive system. Specifically,
the way sh
On Thursday, 11 November 2021 at 21:40:33 UTC, Ali Çehreli wrote:
On 11/11/21 1:37 PM, forkit wrote:
dmd test.d -cov
...but no .lst file anywhere to be found. Huh! I don't get it.
Please run the program! :)
Ali
oh! that kinda makes sense, now that I think of it ;-)
On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote:
Next code originally was a classic C code I've written, it's
pure vertical thinking, now, I converted it successfully to D
code, but I think I made no much changes to make it has more
horizontal thinking style that it seems D program
On Thursday, 11 November 2021 at 21:13:03 UTC, Stanislav Blinov
wrote:
On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote:
It depends on what you're doing. In the OP's example, yeah
worrying about allocations is totally blowing things out of
proportions.
But that's the thing. Ho
// --
module test;
import std.stdio;
void main()
{
writeln("Hello World!");
}
// ---
dmd test.d -cov
..but no .lst file anywhere to be found. Huh! I don't get it.
On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote:
On Wed, Nov 10, 2021 at 11:39:40PM +, forkit via
Digitalmars-d-learn wrote: [...]
I still remember compiling code on my 286x86 ... talk about
low memory..whoaaah.
...
But if you're in a time-constrained inner loop, y
On Wednesday, 10 November 2021 at 23:05:06 UTC, H. S. Teoh wrote:
On Wed, Nov 10, 2021 at 10:17:48PM +, russhy via
Digitalmars-d-learn wrote:
On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote:
> btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache.
> So I really don't give
On Wednesday, 10 November 2021 at 22:17:48 UTC, russhy wrote:
On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote:
btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache.
So I really don't give a damn about allocations .. not one
little bit ;-)
Having the right mindset helps n
On Wednesday, 10 November 2021 at 04:54:58 UTC, Stanislav Blinov
wrote:
On Tuesday, 9 November 2021 at 11:03:09 UTC, forkit wrote:
They both produce exactly the same output.
But do vastly different things.
But I tell ya.. the cognitive load .. well.. it increased
dramatically ;-)
Of cours
On Wednesday, 10 November 2021 at 04:54:58 UTC, Stanislav Blinov
wrote:
On Tuesday, 9 November 2021 at 11:03:09 UTC, forkit wrote:
They both produce exactly the same output.
But do vastly different things.
But I tell ya.. the cognitive load .. well.. it increased
dramatically ;-)
Of cours
On Monday, 8 November 2021 at 12:04:26 UTC, forkit wrote:
On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote:
Next code originally was a classic C code I've written, it's
pure vertical thinking, now, I converted it successfully to D
code, but I think I made no much changes to make it
On Monday, 8 November 2021 at 12:04:26 UTC, forkit wrote:
case 'o' :
result = result.filter!(a => (a % 2 == 1)).array;
oops.
case 'o' :
result = result.filter!(a => (a % 2 != 0)).array;
On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote:
Next code originally was a classic C code I've written, it's
pure vertical thinking, now, I converted it successfully to D
code, but I think I made no much changes to make it has more
horizontal thinking style that it seems D program
101 - 167 of 167 matches
Mail list logo