March 29, 2002 Re: String Comparison and Dynamic Arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a82n7g$oq9$1@digitaldaemon.com... > "Walter" <walter@digitalmars.com> wrote in message news:a82km4$2m2l$2@digitaldaemon.com... > > That would work, but then I'm back to the original point that code that > uses > > ++ on the .length most likely has a severe performance problem, so it's discouraged by not supporting ++. > It wouldn't be slower than ~=, right? And ~= is there... Yes, but ~= is useful for concatenating strings with more than one entry. ++ by definition only adds one, and so is the worst case solution :-( |
March 30, 2002 Re: String Comparison and Dynamic Arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:a82sab$2fjh$1@digitaldaemon.com... > Yes, but ~= is useful for concatenating strings with more than one entry. ++ > by definition only adds one, and so is the worst case solution :-( I often use ~= to build arrays element-by-element: char[] token; ... do { token ~= c; in.read(c); } while (isalpha(c)); The same "worst" case. I thought arrays try to compensate it by allocating memory in blocks? |
April 07, 2002 Re: String Comparison and Dynamic Arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a83g36$1sns$1@digitaldaemon.com... > I often use ~= to build arrays element-by-element: > char[] token; > ... > do > { > token ~= c; > in.read(c); > } while (isalpha(c)); > > The same "worst" case. I thought arrays try to compensate it by allocating memory in blocks? That turned out to have problems implementing it. The trouble was if someone pointed to a slice adjacent to it at a higher memory address. |
April 07, 2002 Re: String Comparison and Dynamic Arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:a8p4l7$105m$1@digitaldaemon.com... > "Pavel Minayev" <evilone@omen.ru> wrote in message news:a83g36$1sns$1@digitaldaemon.com... > > I often use ~= to build arrays element-by-element: > > char[] token; > > ... > > do > > { > > token ~= c; > > in.read(c); > > } while (isalpha(c)); > > > > The same "worst" case. I thought arrays try to compensate it by allocating memory in blocks? > > That turned out to have problems implementing it. The trouble was if someone > pointed to a slice adjacent to it at a higher memory address. I can't understand... what do you mean by "adjancent slice"? |
April 08, 2002 Re: String Comparison and Dynamic Arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a8pask$1d5t$1@digitaldaemon.com... > "Walter" <walter@digitalmars.com> wrote in message news:a8p4l7$105m$1@digitaldaemon.com... > > > "Pavel Minayev" <evilone@omen.ru> wrote in message news:a83g36$1sns$1@digitaldaemon.com... > > > I often use ~= to build arrays element-by-element: > > > char[] token; > > > ... > > > do > > > { > > > token ~= c; > > > in.read(c); > > > } while (isalpha(c)); > > > > > > The same "worst" case. I thought arrays try to compensate it by allocating memory in blocks? > > That turned out to have problems implementing it. The trouble was if > someone > > pointed to a slice adjacent to it at a higher memory address. > I can't understand... what do you mean by "adjancent slice"? char[] a = new char[10]; char[] b = a[5..10]; a.length = 5; a.length = 10; Oops! I just overwrote b! |
April 08, 2002 Re: String Comparison and Dynamic Arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:a8r7up$2nc$1@digitaldaemon.com... > char[] a = new char[10]; > char[] b = a[5..10]; > a.length = 5; > a.length = 10; > > Oops! I just overwrote b! Hm... I thought that, when length increases, the memory is reallocated! |
April 12, 2002 Re: String Comparison and Dynamic Arrays? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a8rnff$14to$1@digitaldaemon.com... > "Walter" <walter@digitalmars.com> wrote in message news:a8r7up$2nc$1@digitaldaemon.com... > > > char[] a = new char[10]; > > char[] b = a[5..10]; > > a.length = 5; > > a.length = 10; > > Oops! I just overwrote b! > Hm... I thought that, when length increases, the memory is reallocated! Yes, and it must be because of that scenario above. |
Copyright © 1999-2021 by the D Language Foundation