Re: String concatenation segmentation error

2021-04-23 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 22 April 2021 at 21:15:48 UTC, tcak wrote: string fileContent = ""; ... [...] Do you have a minimal reproducible test case? 🤔

Re: String concatenation segmentation error

2021-04-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 23 April 2021 at 00:44:58 UTC, tcak wrote: As far as I see, it is not related to that array or indices at all. The question of where is to see if it was CTFE allocated or runtime allocated. I don't think it should make a difference here but idk. If there is no known situation th

Re: String concatenation segmentation error

2021-04-22 Thread tcak via Digitalmars-d-learn
On Friday, 23 April 2021 at 00:30:02 UTC, Adam D. Ruppe wrote: On Thursday, 22 April 2021 at 21:15:48 UTC, tcak wrote: "positions" array is defined as auto positions = new float[ 100 ]; So, I am 100% sure, it is not out of range. "ri*dim + 1" is not a big number at all. Oh and *where* is that

Re: String concatenation segmentation error

2021-04-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 22 April 2021 at 21:15:48 UTC, tcak wrote: "positions" array is defined as auto positions = new float[ 100 ]; So, I am 100% sure, it is not out of range. "ri*dim + 1" is not a big number at all. Oh and *where* is that positions variable defined?

Re: String concatenation segmentation error

2021-04-22 Thread Adam D. Ruppe via Digitalmars-d-learn
Are there any other threads in your program?

Re: String concatenation segmentation error

2021-04-22 Thread tcak via Digitalmars-d-learn
In other parts of the code, concatenation operations are all failing with same error. I need guidance to get out of this situation. My assumption was that as long as there is empty heap memory, concatenation operation would succeed always. But, it doesn't seem like so.

String concatenation segmentation error

2021-04-22 Thread tcak via Digitalmars-d-learn
ll allocation. I remember I had this problem before in another project. I have enough free ram. htop shows 3.96 GiB of 8 GiB is used only and swap is not in use. DMD64 D Compiler v2.094.0 Is this error related to me? Is it a programmer error? Is it a bug? Am I doing something wrong? This is a compiler related operation (string concatenation), and I assume/expect that it would work without a problem.

Re: nogc string concatenation?

2017-07-13 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 14 July 2017 at 00:40:38 UTC, FoxyBrown wrote: Anyone have an efficient implementation that is easy to use? If you are OK with just a range spanning the two or more strings, then you could use chain as is.

Re: nogc string concatenation?

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 14 July 2017 at 00:40:38 UTC, FoxyBrown wrote: Anyone have an efficient implementation that is easy to use? Not sure what you mean by efficient here, but a \theta(n+m) one is done idiomatically with Allocator+ranges like this (note that the casts to and from ubyte are necessary, be

nogc string concatenation?

2017-07-13 Thread FoxyBrown via Digitalmars-d-learn
Anyone have an efficient implementation that is easy to use?

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-04 Thread ketmar via Digitalmars-d-learn
On Friday, 4 November 2016 at 14:56:46 UTC, Guillaume Piolat wrote: On Friday, 4 November 2016 at 14:55:27 UTC, Guillaume Piolat wrote: On Thursday, 3 November 2016 at 18:54:14 UTC, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? I use sprintf + zero

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-04 Thread Guillaume Piolat via Digitalmars-d-learn
On Friday, 4 November 2016 at 14:55:27 UTC, Guillaume Piolat wrote: On Thursday, 3 November 2016 at 18:54:14 UTC, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? I use sprintf + zero-terminated strings (or a RAII struct to convert slices to ZT strings

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-04 Thread Guillaume Piolat via Digitalmars-d-learn
On Thursday, 3 November 2016 at 18:54:14 UTC, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? I use sprintf + zero-terminated strings (or a RAII struct to convert slices to ZT strings).

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/3/16 2:54 PM, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? Where does it go? For instance, this should work: auto newstr = "hello, ".chain("world"); -Steve

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 03, 2016 18:54:14 Gary Willoughby via Digitalmars-d- learn wrote: > What is the simplest way of doing @nogc string concatenation? std.range.chain is the closest that you're going to get with actual strings. Dynamic arrays require the GC to do concatenation, because t

What is the simplest way of doing @nogc string concatenation?

2016-11-03 Thread Gary Willoughby via Digitalmars-d-learn
What is the simplest way of doing @nogc string concatenation?

Re: string concatenation with %s

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:34:20 UTC, Suliman wrote: string sss = format("foo"-", ""bar"); It should be obvious now that you forgot to escape those double quotes. Thanks! Is there any way to stay string as is. without need of it's escaping and so on? It's seems I have seen something li

Re: string concatenation with %s

2015-03-30 Thread Suliman via Digitalmars-d-learn
string sss = format("foo"-", ""bar"); It should be obvious now that you forgot to escape those double quotes. Thanks! Is there any way to stay string as is. without need of it's escaping and so on? It's seems I have seen something like it in docs, but I am not sure about it...

Re: string concatenation with %s

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:18:01 UTC, Suliman wrote: same problem. I am preparing string to next SQL request: string sss = format("SELECT * FROM test.imgs WHERE src LIKE CONCAT('%', REPLACE(CAST(CURDATE()as char), "-", ""), '%') OR CONCAT('%', CAST(CURDATE()as char), '%')"); Here's your

Re: string concatenation with %s

2015-03-30 Thread Suliman via Digitalmars-d-learn
same problem. I am preparing string to next SQL request: string sss = format("SELECT * FROM test.imgs WHERE src LIKE CONCAT('%', REPLACE(CAST(CURDATE()as char), "-", ""), '%') OR CONCAT('%', CAST(CURDATE()as char), '%')"); but I am getting next error: source\app.d(178): Error: invalid array

Re: string concatenation with %s

2015-01-07 Thread novice2 via Digitalmars-d-learn
what if a_college[i] will contain ` char? almost SQL have "prepare" statement...

Re: string concatenation with %s

2015-01-07 Thread Suliman via Digitalmars-d-learn
std.string.format interpolates string with the same behavior as writefln Thanks!

Re: string concatenation with %s

2015-01-07 Thread Suliman via Digitalmars-d-learn
Please show the _clean_ input, followed by an output example. Bye, bearophile to prevent visual corruption I had past it here: http://www.everfall.com/paste/id.php?ftzy9lxr6yfy Just FYI use prepared statements instead of string concatenation for SQL queries. You mean some tools, that

Re: string concatenation with %s

2015-01-07 Thread Justin Whear via Digitalmars-d-learn
On Wed, 07 Jan 2015 16:38:23 +, Suliman wrote: > I except that writefln have some behavior as string concatenation, but > it does not. > > IS there any way to put needed values in place of %s in string? std.string.format interpolates string with the same behavior as writefln

Re: string concatenation with %s

2015-01-07 Thread Gary Willoughby via Digitalmars-d-learn
;, '%s', '%s', '%s', '%s', '%s');", date[i], a_fredericksburg[i], fredericksburg[i], a_college[i], college[i], a_planetary[i], planetary[i]); I except that writefln have some behavior as string concatenation, but it does not. IS ther

Re: string concatenation with %s

2015-01-07 Thread bearophile via Digitalmars-d-learn
27;%s', '%s', '%s');", date[i], a_fredericksburg[i], fredericksburg[i], a_college[i], college[i], a_planetary[i], planetary[i]); I except that writefln have some behavior as string concatenation, but it does not. IS there any way to put needed values in place of %s

string concatenation with %s

2015-01-07 Thread Suliman via Digitalmars-d-learn
%s', '%s');", date[i], a_fredericksburg[i], fredericksburg[i], a_college[i], college[i], a_planetary[i], planetary[i]); I except that writefln have some behavior as string concatenation, but it does not. IS there any way to put needed values in place of %s in string?

Re: Efficient string concatenation?

2013-11-16 Thread Ali Çehreli
On 11/16/2013 08:59 AM, ilya-stromberg wrote: > I think it's good to listen a little critics from newcomers. I belive > that it helps Ali Cehreli to improve the book. Exactly! :) Two quotes from the Introduction chapter: "If you come across chapters that you find to be particularly difficult,

Re: Efficient string concatenation?

2013-11-16 Thread ilya-stromberg
On Friday, 15 November 2013 at 23:51:42 UTC, Jacek Furmankiewicz wrote: Thanks for the book! I printed it, all 673 pages of it. Immense work you have there. I think it's good to listen a little critics from newcomers. I belive that it helps Ali Cehreli to improve the book. Also, you can use

Re: Efficient string concatenation?

2013-11-16 Thread JR
On Friday, 15 November 2013 at 22:33:34 UTC, Brad Anderson wrote: Appender in std.array is probably what you are looking for. std.algorithm.joiner is also useful (no allocations at all even) but the use case is a bit different. Is Appender considered up to Phobos' current standards? I vaguely

Re: Efficient string concatenation?

2013-11-15 Thread Jacek Furmankiewicz
Thanks for the book! I printed it, all 673 pages of it. Immense work you have there.

Re: Efficient string concatenation?

2013-11-15 Thread Ali Çehreli
On 11/15/2013 02:35 PM, Jacek Furmankiewicz wrote: > "Programming in D" PDF and he did not show this in his initial chapter on > Strings. Sorry about that. :) As I was targeting novices to programming, I tried to give as much as needed but as little as possible, so that the reader would not be

Re: Efficient string concatenation?

2013-11-15 Thread qznc
On Friday, 15 November 2013 at 22:35:48 UTC, Jacek Furmankiewicz wrote: I am learning D by going through Ali Cehreli's otherwise excellent "Programming in D" PDF and he did not show this in his initial chapter on Strings. Well, Appender is not string specific. D feels like being in a differen

Re: Efficient string concatenation?

2013-11-15 Thread Jacek Furmankiewicz
Thank you all. I am learning D by going through Ali Cehreli's otherwise excellent "Programming in D" PDF and he did not show this in his initial chapter on Strings.

Re: Efficient string concatenation?

2013-11-15 Thread Justin Whear
On Fri, 15 Nov 2013 22:30:35 +, Justin Whear wrote: > std.array has an Appender type that can be used to build up a string (or > any other array type) efficiently. Oh, and if you have an idea of how large the result might grow, be sure to use the reserve() method on the appender.

Re: Efficient string concatenation?

2013-11-15 Thread Brad Anderson
On Friday, 15 November 2013 at 22:26:20 UTC, Jacek Furmankiewicz wrote: Since D strings are immutable (like in most other languages), string concatenation is usually pretty inefficient due to the need to create a new copy of the string every time. I presume string concatenation using the

Re: Efficient string concatenation?

2013-11-15 Thread Justin Whear
On Fri, 15 Nov 2013 23:26:19 +0100, Jacek Furmankiewicz wrote: > Since D strings are immutable (like in most other languages), string > concatenation is usually pretty inefficient due to the need to create a > new copy of the string every time. > > I presume string concaten

Efficient string concatenation?

2013-11-15 Thread Jacek Furmankiewicz
Since D strings are immutable (like in most other languages), string concatenation is usually pretty inefficient due to the need to create a new copy of the string every time. I presume string concatenation using the typical array syntax can be optimized by the compiler to do all of this in

Re: Tips for fast string concatenation?

2013-06-21 Thread Steven Schveighoffer
On Fri, 21 Jun 2013 06:14:38 -0400, Jonathan M Davis wrote: On Friday, June 21, 2013 12:09:09 Gary Willoughby wrote: Have you any tips for using D when you need fast string concatenation? I regularly use code like this: foreach (i, range) { foo ~= bar; } or

Re: Tips for fast string concatenation?

2013-06-21 Thread Namespace
It's worth pointing out that Appender supports ~= so it's very easy to swap it in, replacing builtin concatenation. This works since 2.062 AFAIK. So is still quite new.

Re: Tips for fast string concatenation?

2013-06-21 Thread John Colvin
On Friday, 21 June 2013 at 11:33:29 UTC, monarch_dodra wrote: On Friday, 21 June 2013 at 10:09:10 UTC, Gary Willoughby wrote: Have you any tips for using D when you need fast string concatenation? I regularly use code like this: foreach (i, range) { foo ~= bar; } or: foo

Re: Tips for fast string concatenation?

2013-06-21 Thread monarch_dodra
On Friday, 21 June 2013 at 10:09:10 UTC, Gary Willoughby wrote: Have you any tips for using D when you need fast string concatenation? I regularly use code like this: foreach (i, range) { foo ~= bar; } or: foo = foo ~ bar ~ baz ~ qux; I've used std.string.f

Re: Tips for fast string concatenation?

2013-06-21 Thread Jonathan M Davis
On Friday, June 21, 2013 12:09:09 Gary Willoughby wrote: > Have you any tips for using D when you need fast string > concatenation? I regularly use code like this: > > foreach (i, range) > { > foo ~= bar; > } > > or: > > foo = foo

Re: Tips for fast string concatenation?

2013-06-21 Thread Vladimir Panteleev
On Friday, 21 June 2013 at 10:09:10 UTC, Gary Willoughby wrote: Are there faster ways of appending strings? You'll want to use appender, from std.array: http://dlang.org/phobos/std_array.html#.Appender

Tips for fast string concatenation?

2013-06-21 Thread Gary Willoughby
Have you any tips for using D when you need fast string concatenation? I regularly use code like this: foreach (i, range) { foo ~= bar; } or: foo = foo ~ bar ~ baz ~ qux; I've used std.string.format(...) in some instances which sped things up which surpris

Re: string concatenation

2012-04-09 Thread Steven Schveighoffer
On Sun, 08 Apr 2012 01:08:09 -0400, dnewbie wrote: I have a wchar[] and I want to convert it to UTF8 then append a string. This is my code. import std.c.windows.windows; import std.string; import std.utf; int main() { wchar[100] v; v[0] = 'H'; v[1] = 'e'; v[2] = 'l'; v[3] = 'l'

Re: string concatenation

2012-04-08 Thread Stefan
On Sunday, 8 April 2012 at 05:08:15 UTC, dnewbie wrote: wchar[100] v; v[0] = 'H'; v[1] = 'e'; v[2] = 'l'; v[3] = 'l'; v[4] = 'o'; v[5] = 0; string s = toUTF8(v) ~ ", world!"; MessageBoxA(null, s.toStringz, "myapp", MB_OK); Hint: You normally don't use fixed-length arr

Re: string concatenation

2012-04-08 Thread dnewbie
On Sunday, 8 April 2012 at 05:27:50 UTC, Jonathan M Davis wrote: On Sunday, April 08, 2012 07:08:09 dnewbie wrote: I have a wchar[] and I want to convert it to UTF8 then append a string. This is my code. import std.c.windows.windows; import std.string; import std.utf; int main() { wchar[100

Re: string concatenation

2012-04-08 Thread bearophile
dnewbie: string s = toUTF8(v) ~ ", world!"; MessageBoxA(null, s.toStringz, "myapp", MB_OK); return 0; } I suggest to compile all your code with -property plus -w (or -wi), unless you have some specific needs to not do it. Bye, bearophile

Re: string concatenation

2012-04-08 Thread Andrej Mitrovic
On 4/8/12, dnewbie wrote: > I have a wchar[] and I want to convert it to UTF8 > then append a string. This is my code. > > import std.c.windows.windows; > import std.string; > import std.utf; > > int main() > { >wchar[100] v; >v[0] = 'H'; >v[1] = 'e'; >v[2] = 'l'; >v[3] = 'l';

Re: string concatenation

2012-04-07 Thread Jonathan M Davis
On Sunday, April 08, 2012 07:08:09 dnewbie wrote: > I have a wchar[] and I want to convert it to UTF8 > then append a string. This is my code. > > import std.c.windows.windows; > import std.string; > import std.utf; > > int main() > { >wchar[100] v; >v[0] = 'H'; >v[1] = 'e'; >v[2]

string concatenation

2012-04-07 Thread dnewbie
I have a wchar[] and I want to convert it to UTF8 then append a string. This is my code. import std.c.windows.windows; import std.string; import std.utf; int main() { wchar[100] v; v[0] = 'H'; v[1] = 'e'; v[2] = 'l'; v[3] = 'l'; v[4] = 'o'; v[5] = 0; string s = toUTF8(v) ~

Re: Freeing memory after string concatenation

2008-12-23 Thread Sean Kelly
Alex wrote: Hey, I got a problem after concatenating two strings: void main() { while(true) // For faking high program activity... { string t="Do"; string t2="That" foo(t,t2); delete t; delete t2; No

Re: Freeing memory after string concatenation

2008-12-23 Thread bearophile
I am using D1, while you probably use D2. I have compiled the following code with -O -release -inline, with the last DMD 1.x: import std.stdio: writefln; void foo(string s1, string s2) { string con = s1 ~ s2; writefln(con); } void main() { while(true) { string t1 = "Do";

Freeing memory after string concatenation

2008-12-23 Thread Alex
Hey, I got a problem after concatenating two strings: void main() { while(true) // For faking high program activity... { string t="Do"; string t2="That" foo(t,t2); delete t; delete t2; } } void fo