Re: Problem with clear on shared associative array?

2024-05-27 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 28/05/2024 12:36 PM, Andy Valencia wrote: On Monday, 27 May 2024 at 04:04:03 UTC, mw wrote: Pls NOTE: it is a   `sharded` (meaning trunk-ed) NON-concurrent map, not `shared` concurrent map. Assuming I put it in shared memory, in what way is it not able to be used concurrently?  It seems to

Re: Problem with clear on shared associative array?

2024-05-27 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 27 May 2024 at 04:04:03 UTC, mw wrote: Pls NOTE: it is a `sharded` (meaning trunk-ed) NON-concurrent map, not `shared` concurrent map. Assuming I put it in shared memory, in what way is it not able to be used concurrently? It seems to have the needed lock operations? Thanks, A

Re: Problem with clear on shared associative array?

2024-05-26 Thread mw via Digitalmars-d-learn
On Monday, 27 May 2024 at 00:43:47 UTC, Serg Gini wrote: On Sunday, 26 May 2024 at 20:15:54 UTC, Andy Valencia wrote: For others wrestling with this issue, I found out how to cast to unshared at this article: You can check also this solution https://github.com/DmitryOlshansky/sharded-map

Re: Problem with clear on shared associative array?

2024-05-26 Thread Serg Gini via Digitalmars-d-learn
On Sunday, 26 May 2024 at 20:15:54 UTC, Andy Valencia wrote: For others wrestling with this issue, I found out how to cast to unshared at this article: You can check also this solution https://github.com/DmitryOlshansky/sharded-map

Re: Problem with clear on shared associative array?

2024-05-26 Thread Andy Valencia via Digitalmars-d-learn
On Sunday, 26 May 2024 at 20:00:50 UTC, Jonathan M Davis wrote: No operation on an associative array is thread-safe. As such, you should not be doing _any_ operation on a shared AA without first locking a mutex to protect it. Then you need to cast away shared to access or mutate it or do whatev

Re: Problem with clear on shared associative array?

2024-05-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 26, 2024 8:39:53 AM MDT Andy Valencia via Digitalmars-d-learn wrote: > The following code fails to compile; it appears from the error > message that the library's clear() function is not ready to act > on a shared AA? > > synchronized class F { > >

Problem with clear on shared associative array?

2024-05-26 Thread Andy Valencia via Digitalmars-d-learn
The following code fails to compile; it appears from the error message that the library's clear() function is not ready to act on a shared AA? synchronized class F { private: string[int] mydict; public: void clear() { this.mydict.clear(); } } void main() { a

Re: How to "Clear the Screen" for Windows Command Processor? (Windows 10)

2019-05-21 Thread BoQsc via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 12:51:41 UTC, Adam D. Ruppe wrote: On Tuesday, 21 May 2019 at 07:16:29 UTC, Boqsc wrote: I'm getting unsure why executeShell works on the pause command, but cls that is responsible for clearing the text do not. When you ran pause, did it print the text "press any ke

Re: How to "Clear the Screen" for Windows Command Processor? (Windows 10)

2019-05-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 07:16:29 UTC, Boqsc wrote: I'm getting unsure why executeShell works on the pause command, but cls that is responsible for clearing the text do not. When you ran pause, did it print the text "press any key to continue"? executeShell captures the output of the progr

Re: How to "Clear the Screen" for Windows Command Processor? (Windows 10)

2019-05-21 Thread BoQsc via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 10:03:38 UTC, KnightMare wrote: try next: spawnShell( "cls" ).wait; Wow, spawnShell indeed does the job as I would expect, as of right now. Thanks. spawnShell Function indeed sounds like it would spawn a new shell instead of what it does, at first I didn't look in

Re: How to "Clear the Screen" for Windows Command Processor? (Windows 10)

2019-05-21 Thread KnightMare via Digitalmars-d-learn
try next: spawnShell( "cls" ).wait;

Re: How to "Clear the Screen" for Windows Command Processor? (Windows 10)

2019-05-21 Thread Jim via Digitalmars-d-learn
ear in cmd"); executeShell("cls"); // Does not clear the text? executeShell("pause"); // Pauses the cmd.exe to keep from closing itself. } As far as I understand [1], executeShell starts a new shell and executes %command% in that shell. So cls wouldn't be called in the shell

How to "Clear the Screen" for Windows Command Processor? (Windows 10)

2019-05-21 Thread Boqsc via Digitalmars-d-learn
I'm getting unsure why executeShell works on the pause command, but cls that is responsible for clearing the text do not. import std.stdio, std.process; void main() { writeln("Some text that will appear in cmd"); executeShell("cls"); // Does not clea

Re: Best way to clear dynamic array for reuse

2016-12-28 Thread Nemanja Boric via Digitalmars-d-learn
On Wednesday, 28 December 2016 at 12:30:33 UTC, Michael Rynn wrote: It takes a bit of work to get around the mutable buffers problem in D language arrays. I found it made a performance difference in xml parsing. https://github.com/betrixed/dlang-xml/blob/master/xml/util/buffer.d /**

Best way to clear dynamic array for reuse

2016-12-28 Thread Michael Rynn via Digitalmars-d-learn
It takes a bit of work to get around the mutable buffers problem in D language arrays. I found it made a performance difference in xml parsing. https://github.com/betrixed/dlang-xml/blob/master/xml/util/buffer.d /** Buffer(T) - Versatile appendable D array for buffer reuse, append, re

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/16 5:56 AM, Miguel L wrote: On Thursday, 14 July 2016 at 09:12:50 UTC, Jonathan M Davis wrote: So, whether you should be using Appender or assumeSafeAppend or neither depends entirely on what you're doing. However, in general, simply appending to dynamic arrays does not result in many re

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 14, 2016 09:56:02 Miguel L via Digitalmars-d-learn wrote: > Thank you Jonathan, that really cleared up a lot of things, I > read the article. But I still have this doubt: is > assumeSafeAppend() changing a property of the array as "this > array is never going to be referenced by a

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Miguel L via Digitalmars-d-learn
On Thursday, 14 July 2016 at 09:12:50 UTC, Jonathan M Davis wrote: So, whether you should be using Appender or assumeSafeAppend or neither depends entirely on what you're doing. However, in general, simply appending to dynamic arrays does not result in many reallocations (just like it doesn't r

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 14, 2016 07:07:52 Miguel L via Digitalmars-d-learn wrote: > Ok, i have read about Appender and assumeSafeAppend(), but i am > still a bit confused. > What i have understood is: dynamic arrays are (almost) always > reallocating when appending to them except assumeSafeAppend() is >

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Miguel L via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 17:19:09 UTC, Steven Schveighoffer wrote: On 7/13/16 8:41 AM, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 12:37:26 UTC, Miguel L wrote: I tried Appender, but for some reason garbage collector still seems to be running every few iterations. I will try to

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/13/16 8:41 AM, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 12:37:26 UTC, Miguel L wrote: I tried Appender, but for some reason garbage collector still seems to be running every few iterations. I will try to expand a little on my code because maybe there is something i am missing:

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Jonathan M Davis via Digitalmars-d-learn
t; } > > I would like to know which would be the best way to clear a > contents avoiding reallocations, as there seems to be lots of > garbage collection cycles taking place. > > The options would be: > > a=[]; > a.length=0; > a=null; > ... > any other? > > C

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 12:37:26 UTC, Miguel L wrote: I tried Appender, but for some reason garbage collector still seems to be running every few iterations. I will try to expand a little on my code because maybe there is something i am missing: Appender!(A[]) a; void foo( out Appende

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Miguel L via Digitalmars-d-learn
some calculations } I would like to know which would be the best way to clear a contents avoiding reallocations, as there seems to be lots of garbage collection cycles taking place. The options would be: a=[]; a.length=0; a=null; ... any other? Can you help me please? Use std.array.Appender

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Mathias Lang via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 12:05:12 UTC, rikki cattermole wrote: On 13/07/2016 11:59 PM, Miguel L wrote: The options would be: a=[]; a.length=0; a=null; ... any other? Can you help me please? All of those "options" do the same thing, remove all references to that data. No they don't. T

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread cym13 via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 12:22:55 UTC, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 12:20:07 UTC, cym13 wrote: The best option would be a.clear(). From the language specs: “Removes all remaining keys and values from an associative array. The array is not rehashed after removal,

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 12:20:07 UTC, cym13 wrote: The best option would be a.clear(). From the language specs: “Removes all remaining keys and values from an associative array. The array is not rehashed after removal, to allow for the existing storage to be reused. This will affect all

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread cym13 via Digitalmars-d-learn
clear a contents avoiding reallocations, as there seems to be lots of garbage collection cycles taking place. The options would be: a=[]; a.length=0; a=null; ... any other? Can you help me please? The best option would be a.clear(). From the language specs: “Removes all remaining keys and

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread ketmar via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 11:59:18 UTC, Miguel L wrote: The options would be: a=[]; a.length=0; a=null; ... any other? it really depends of your other code. if you don't have any slices of the array, for example, you can use `a.length = 0; a.assumeSafeAppend;` -- this will reuse the allo

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Lodovico Giaretta via Digitalmars-d-learn
clear a contents avoiding reallocations, as there seems to be lots of garbage collection cycles taking place. The options would be: a=[]; a.length=0; a=null; ... any other? Can you help me please? Use std.array.Appender. It allows faster appends, and has a handy .clear method that zeroes

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread rikki cattermole via Digitalmars-d-learn
On 13/07/2016 11:59 PM, Miguel L wrote: I am using a temporary dynamic array inside a loop this way: A[] a; for() { a=[]; //discard array contents ... appends thousand of elements to a ... use a for some calculations } I would like to know which would be the best way to clear a contents

Best way to clear dynamic array for reuse

2016-07-13 Thread Miguel L via Digitalmars-d-learn
I am using a temporary dynamic array inside a loop this way: A[] a; for() { a=[]; //discard array contents ... appends thousand of elements to a ... use a for some calculations } I would like to know which would be the best way to clear a contents avoiding reallocations, as there seems to

Re: Is there a way to clear an OutBuffer?

2016-05-25 Thread Jon Degenhardt via Digitalmars-d-learn
aps? :) Ali Thanks. Enhancement request: https://issues.dlang.org/show_bug.cgi?id=16062 Is there a consensus on this? Does this really need a clear method seeing as though you can reset the offset directly? As an end-user, I'd have more confidence using a documented mechanism. If it'

Re: Is there a way to clear an OutBuffer?

2016-05-25 Thread Gary Willoughby via Digitalmars-d-learn
ow_bug.cgi?id=16062 Is there a consensus on this? Does this really need a clear method seeing as though you can reset the offset directly?

Re: Is there a way to clear an OutBuffer?

2016-05-23 Thread Seb via Digitalmars-d-learn
On Monday, 23 May 2016 at 03:03:12 UTC, Jon Degenhardt wrote: On Sunday, 22 May 2016 at 23:01:07 UTC, Ali Çehreli wrote: On 05/22/2016 11:59 AM, Jon Degenhardt wrote: [...] Currently not possible. Enhancement request perhaps? Looking at the implementation, setting its 'offset' member seems

Re: Is there a way to clear an OutBuffer?

2016-05-22 Thread Jon Degenhardt via Digitalmars-d-learn
On Sunday, 22 May 2016 at 23:01:07 UTC, Ali Çehreli wrote: On 05/22/2016 11:59 AM, Jon Degenhardt wrote: Is there a way to clear an OutBuffer, but without freeing the internally managed buffer? Something similar to std.array.appender.clear method. Intent would be to reuse the OutBuffer, but

Re: Is there a way to clear an OutBuffer?

2016-05-22 Thread Ali Çehreli via Digitalmars-d-learn
On 05/22/2016 11:59 AM, Jon Degenhardt wrote: Is there a way to clear an OutBuffer, but without freeing the internally managed buffer? Something similar to std.array.appender.clear method. Intent would be to reuse the OutBuffer, but without reallocating memory for the buffer. --Jon Currently

Is there a way to clear an OutBuffer?

2016-05-22 Thread Jon Degenhardt via Digitalmars-d-learn
Is there a way to clear an OutBuffer, but without freeing the internally managed buffer? Something similar to std.array.appender.clear method. Intent would be to reuse the OutBuffer, but without reallocating memory for the buffer. --Jon

Re: `clear`ing a dynamic array

2015-10-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 25, 2015 17:15:50 Shriramana Sharma via Digitalmars-d-learn wrote: > Jonathan M Davis via Digitalmars-d-learn wrote: > > > Appender really isn't intended to be used as a > > container - just as a way to make appending more efficient or to have an > > output range which is an arr

Re: `clear`ing a dynamic array

2015-10-25 Thread Jonathan M Davis via Digitalmars-d-learn
re wasn't enough room to append another element when an append operation was attempted), then two dynamic arrays which referred to the same memory would then refer to completely different memory. You started out this thread talking about how you wanted to be able to "clear" a dyna

Re: `clear`ing a dynamic array

2015-10-25 Thread Shriramana Sharma via Digitalmars-d-learn
anonymous wrote: >> I presume this means >> http://dlang.org/phobos/std_array.html#.Appender.reserve but >> how `append` is considered an operator is beyond me. > > That sentence doesn't refer to std.array.Appender. `reserve` > means . The append > op

Re: `clear`ing a dynamic array

2015-10-25 Thread anonymous via Digitalmars-d-learn
On Sunday, 25 October 2015 at 11:45:53 UTC, Shriramana Sharma wrote: http://dlang.org/arrays.html#resize says: """Also, you may wish to utilize the phobos reserve function to pre-allocate array data to use with the append operator.""" I presume this means http://dlang.org/phobos/std_array.htm

Re: `clear`ing a dynamic array

2015-10-25 Thread Shriramana Sharma via Digitalmars-d-learn
Jonathan M Davis via Digitalmars-d-learn wrote: > Appender really isn't intended to be used as a > container - just as a way to make appending more efficient or to have an > output range which is an array I get the part about Appender helping to make an output range of a regular array, but I'm n

Re: `clear`ing a dynamic array

2015-10-25 Thread Shriramana Sharma via Digitalmars-d-learn
Thanks all, for your replies. Jonathan M Davis via Digitalmars-d-learn wrote: > If you want a container rather than a dynamic array - especially if you're > looking for full reference semantics - then use std.container.array.Array. Hmmm, pardon me but while I'm sure I don't specifically require

Re: `clear`ing a dynamic array

2015-10-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 25, 2015 09:34:25 Shriramana Sharma via Digitalmars-d-learn wrote: > rsw0x wrote: > > > use std.container.array > > Thanks all for all the recommendations. When would one use > std.array.appender with a built-in array vs std.container.array.Array? What > are the pros and cons on

Re: `clear`ing a dynamic array

2015-10-25 Thread Olivier Pisano via Digitalmars-d-learn
On Sunday, 25 October 2015 at 04:04:29 UTC, Shriramana Sharma wrote: rsw0x wrote: use std.container.array Thanks all for all the recommendations. When would one use std.array.appender with a built-in array vs std.container.array.Array? What are the pros and cons on either side? Appender

Re: `clear`ing a dynamic array

2015-10-24 Thread qsdfghjk via Digitalmars-d-learn
On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote: Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unw

Re: `clear`ing a dynamic array

2015-10-24 Thread Shriramana Sharma via Digitalmars-d-learn
rsw0x wrote: > use std.container.array Thanks all for all the recommendations. When would one use std.array.appender with a built-in array vs std.container.array.Array? What are the pros and cons on either side? -- Shriramana Sharma, Penguin #395953

Re: `clear`ing a dynamic array

2015-10-24 Thread rsw0x via Digitalmars-d-learn
On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote: Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unw

Re: `clear`ing a dynamic array

2015-10-24 Thread John Colvin via Digitalmars-d-learn
On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote: Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unw

Re: `clear`ing a dynamic array

2015-10-24 Thread anonymous via Digitalmars-d-learn
On 24.10.2015 15:18, Shriramana Sharma wrote: int a[] = [1,2,3,4,5]; Aside: `int[] a;` is the preferred style for array declarations. How to make it so that after clearing `a`, `b` will also point to the same empty array? IOW the desired output is: [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [] [] .

Re: `clear`ing a dynamic array

2015-10-24 Thread Cauterite via Digitalmars-d-learn
b.length' through 'a'. To get that effect, you'd have to do something like this: int[] a = [1,2,3,4,5]; int[]* b = &a; a = []; assert(*b == [] && b.length == 0); On Saturday, 24 October 2015 at 13:18:26 UTC, Shriramana Sharma wrote:

`clear`ing a dynamic array

2015-10-24 Thread Shriramana Sharma via Digitalmars-d-learn
Hello. I had first expected that dynamic arrays (slices) would provide a `.clear()` method but they don't seem to. Obviously I can always effectively clear an array by assigning an empty array to it, but this has unwanted consequences that `[]` actually seems to allocate a new dynamic arra

Re: clear works better than it ought to considered i never defined it

2014-07-27 Thread Vlad Levenfeld via Digitalmars-d-learn
Yep, just checked in the debugger. So, that's actually a bad thing, then. Good thing its being deprecated!

Re: clear works better than it ought to considered i never defined it

2014-07-27 Thread Mike via Digitalmars-d-learn
On Monday, 28 July 2014 at 06:27:44 UTC, Vlad Levenfeld wrote: A weird thing happened: I was building a dictionary struct which contains a custom array of values and a differently-typed custom array of keys. Both of them implicitly define "clear" by aliasing a backing array. The

clear works better than it ought to considered i never defined it

2014-07-27 Thread Vlad Levenfeld via Digitalmars-d-learn
A weird thing happened: I was building a dictionary struct which contains a custom array of values and a differently-typed custom array of keys. Both of them implicitly define "clear" by aliasing a backing array. The dictionary type doesn't have clear, though. And it doesn&#x

Re: How i can clear Associative Arrays

2013-04-28 Thread Marco Leise
. Either > >>> through Druntime or through a UFCS function that we could put in > >>> std.array or somewhere. > >> > >> How about .clear() for consistency with C++ containers? > > > > It looks nice... i am waiting for it :P > > Might be c

Re: How i can clear Associative Arrays

2013-04-15 Thread Michael
On Monday, 15 April 2013 at 11:36:55 UTC, Tobias Pankrath wrote: You could set the length to 0. Before version 4.0 in C# a Clear extension-method just calls Collection.length = 0; Later this method was included to BCL. In D length property for AA is readonly.

Re: How i can clear Associative Arrays

2013-04-15 Thread Steven Schveighoffer
.clear() for consistency with C++ containers? It looks nice... i am waiting for it :P Might be confusing. clear used to do what destroy does now and is still in TDPL. -Steve

Re: How i can clear Associative Arrays

2013-04-15 Thread Andrea Fontana
Not on associative arrays afaik. On Monday, 15 April 2013 at 11:36:55 UTC, Tobias Pankrath wrote: You could set the length to 0.

Re: How i can clear Associative Arrays

2013-04-15 Thread Tobias Pankrath
You could set the length to 0.

Re: How i can clear Associative Arrays

2013-04-15 Thread Andrea Fontana
.clear() for consistency with C++ containers? It looks nice... i am waiting for it :P If you can't do myArray = null, you can define this: void removeAll(T, K)(T[K] arr) { foreach(k; arr.keys) arr.remove(k); } or this: import std.traits; void removeAll(T)(T ar

Re: How i can clear Associative Arrays

2013-04-13 Thread gedaiu
On Saturday, 13 April 2013 at 21:10:16 UTC, Nicolas Guillemot wrote: I think we should introduce a removeAll function for hashes. Either through Druntime or through a UFCS function that we could put in std.array or somewhere. How about .clear() for consistency with C++ containers? It looks

Re: How i can clear Associative Arrays

2013-04-13 Thread Nicolas Guillemot
I think we should introduce a removeAll function for hashes. Either through Druntime or through a UFCS function that we could put in std.array or somewhere. How about .clear() for consistency with C++ containers?

Re: How i can clear Associative Arrays

2013-04-13 Thread Andrej Mitrovic
On 4/13/13, gedaiu wrote: > I know, that's why I am asking how i should do this... I think we should introduce a removeAll function for hashes. Either through Druntime or through a UFCS function that we could put in std.array or somewhere. Putting it in Druntime is probably the most efficient wa

Re: How i can clear Associative Arrays

2013-04-13 Thread gedaiu
hash[1] = 1; auto hash2 = hash; // new reference hash = null; // clear the reference assert(1 in hash2); // hash still exists } I know, that's why I am asking how i should do this...

Re: How i can clear Associative Arrays

2013-04-13 Thread Andrej Mitrovic
nce hash = null; // clear the reference assert(1 in hash2); // hash still exists }

Re: How i can clear Associative Arrays

2013-04-13 Thread Nicolas Guillemot
values = null; and it seems it works great. But, i don't know how correct is this... I was expecting to have a clear() method on array. Makes sense to me! Looks like the technique you described is explained here: http://ddili.org/ders/d.en/null_is.html Good find, thanks for sharing!

Re: How i can clear Associative Arrays

2013-04-13 Thread gedaiu
t, i don't know how correct is this... I was expecting to have a clear() method on array. Thanks, Bogdan

Re: How i can clear Associative Arrays

2013-04-13 Thread Nicolas Guillemot
Hey gedaiu, I'm still a novice to D, but here are some solutions I found. They can probably be improved. 1) Assigning to it an empty map https://ideone.com/h7ffmD 2) Removing all entries https://ideone.com/E7k2WL My guess is that the first method is more efficient. I wish I knew how to do i

How i can clear Associative Arrays

2013-04-13 Thread gedaiu
Hi, I have an associative array: string values[string], and i want to remove all the values from this array. I looked at the documentation here: http://dlang.org/hash-map.html and i can't see any method for this action. There is a nice way to remove the values, or I should use foreach? Than

Re: clear array

2012-10-15 Thread bearophile
Damian: destroy and clear work nicely, except when using large arrays dmd is taking quite a while to compile int[1000][1000] arr; destroy(arr); Unfortunately currently DMD/druntime is not designed to handle large fixed-sized arrays well, in general (large static floating point or char 2D

Re: clear array

2012-10-15 Thread Damian
On Tuesday, 16 October 2012 at 00:44:15 UTC, Jonathan M Davis wrote: On Tuesday, October 16, 2012 02:37:52 Andrej Mitrovic wrote: On 10/16/12, Damian wrote: > Does D have a built-in way to clear arrays dynamic and > static? clear(arr). arr.clear() should work too. Use destroy, not

Re: clear array

2012-10-15 Thread Damian
On Tuesday, 16 October 2012 at 00:47:44 UTC, H. S. Teoh wrote: On Tue, Oct 16, 2012 at 02:33:03AM +0200, Damian wrote: I know this is a bit of a dumb question and I have searched and not found anything concrete surprisingly :/ Does D have a built-in way to clear arrays dynamic and static? I

Re: clear array

2012-10-15 Thread H. S. Teoh
On Tue, Oct 16, 2012 at 02:33:03AM +0200, Damian wrote: > I know this is a bit of a dumb question and I have searched and not > found anything concrete surprisingly :/ > > Does D have a built-in way to clear arrays dynamic and static? > I don't want to iterate over every eleme

Re: clear array

2012-10-15 Thread Jonathan M Davis
On Tuesday, October 16, 2012 02:37:52 Andrej Mitrovic wrote: > On 10/16/12, Damian wrote: > > Does D have a built-in way to clear arrays dynamic and static? > > clear(arr). > arr.clear() should work too. Use destroy, not clear. clear is now an alias for clear and sho

Re: clear array

2012-10-15 Thread Adam D. Ruppe
On Tuesday, 16 October 2012 at 00:33:04 UTC, Damian wrote: In C++ I would just use memset, I don't know if I should be using this for D? The direct D analog to memset is: int[] arr; arr[] = 0; // or whatever You can assign a value to a whole slice in a single go. arr[] means return a slice

clear array

2012-10-15 Thread Damian
I know this is a bit of a dumb question and I have searched and not found anything concrete surprisingly :/ Does D have a built-in way to clear arrays dynamic and static? I don't want to iterate over every element and set a default value. In C++ I would just use memset, I don't

Re: Missing destructor call using clear and base interface ref.

2012-08-09 Thread Denis Shelomovskij
09.08.2012 12:36, Roberto Delfiore пишет: Thank you for your analysis, it's a very strange behavior. I still can not figure out if there is something I don't know or if it's is simply a bug. Good answer: Shouldn't destroy() work on an interface? Filled an issue: http://d.puremagic.com/issues/

Re: Missing destructor call using clear and base interface ref.

2012-08-09 Thread Roberto Delfiore
08/06/2012 06:59 AM, Roberto Delfiore wrote: > See the following code: > > interface A{ > } > > class B : A{ > this(string name){this.name = name;} > ~this(){ > writefln("Destructor %s", name); > } > string name; > } > > void main(){ > B b0

Re: Missing destructor call using clear and base interface ref.

2012-08-06 Thread Ali Çehreli
B b0 = new B("b0"); > B b1 = new B("b1"); > > A a = b0; > clear(a); > > clear(b1); > } > > Output: > Destructor b1 > > dmd 2.059 > > Why is the B destructor not invoked in the first clear? > > Expected output: > Destructor b0 &g

Missing destructor call using clear and base interface ref.

2012-08-06 Thread Roberto Delfiore
See the following code: interface A{ } class B : A{ this(string name){this.name = name;} ~this(){ writefln("Destructor %s", name); } string name; } void main(){ B b0 = new B("b0"); B b1 = new B("b1"); A a = b0; clear

Re: AA clear property

2011-11-06 Thread Alex_Dovhal
Thakns for details. Arfer another small benchmark, it appeared that addition to AA is 10x times slower than removal from it. So that's why (2) isn't so bad in my previous tests - most of time AA was adding elements to remove later. Anyway if (2) also reallocates it's much much worse that (1).

Re: AA clear property

2011-11-06 Thread Jonathan M Davis
On Sunday, November 06, 2011 04:11:07 Jonathan M Davis wrote: > On Sunday, November 06, 2011 13:39:27 Alex_Dovhal wrote: > > "Marco Leise" wrote: > > > No way I heard of. You could delete the entries one by one. :D > > > I guess setting all references

Re: AA clear property

2011-11-06 Thread Jonathan M Davis
On Sunday, November 06, 2011 13:39:27 Alex_Dovhal wrote: > "Marco Leise" wrote: > > No way I heard of. You could delete the entries one by one. :D > > I guess setting all references to null is the easiest way to 'clear' an > > AA. > > Thanks. I tri

Re: AA clear property

2011-11-06 Thread Alex_Dovhal
"Marco Leise" wrote: > No way I heard of. You could delete the entries one by one. :D > I guess setting all references to null is the easiest way to 'clear' an > AA. Thanks. I tried both of them in small benchmark. Results are (1) fill_values(aa); aa = null (

Re: AA clear property

2011-11-06 Thread Marco Leise
ng all references to null is the easiest way to 'clear' an AA.

Re: AA clear property

2011-11-05 Thread Alex_Dovhal
"Marco Leise" wrote: > Are you this Alex? yes. > As I understand it this function is defined in object_.d which is always > imported by default and can be called on an (associative) array through a > mechanism called "universal function call", that matches the part before > the dot with the fi

Re: AA clear property

2011-11-05 Thread Marco Leise
Am 05.11.2011, 21:30 Uhr, schrieb Alex_Dovhal : Hi, D have "clear" property for arrays and AA, but I failed to find it's description in docs. Where it's? Are you this Alex? http://aichallenge.org/forums/viewtopic.php?f=21&t=1315#p10776 As I understand it this functi

AA clear property

2011-11-05 Thread Alex_Dovhal
Hi, D have "clear" property for arrays and AA, but I failed to find it's description in docs. Where it's?

Re: clear bug?

2011-09-06 Thread Steven Schveighoffer
might have changed but how would someone new to D know that? I really don't pay much attention to clear, since I rarely use it, and I don't know why you'd ever actually want to try and use an object that you cleared. I do remember discussions about making it clear out the vtable, sin

Re: clear bug?

2011-09-05 Thread Jonathan M Davis
been cleared? > >> > >> TDPL, that's why. Things might have changed but how would someone new > >> to D know that? > > > > I really don't pay much attention to clear, since I rarely use it, and I > > don't know why you'd ever actua

Re: clear bug?

2011-09-05 Thread Dan Olson
anged but how would someone new >> to D know that? > > I really don't pay much attention to clear, since I rarely use it, and I > don't > know why you'd ever actually want to try and use an object that you cleared. > I > do remember discussions about making it

Re: clear bug?

2011-09-05 Thread Jonathan M Davis
hat? I really don't pay much attention to clear, since I rarely use it, and I don't know why you'd ever actually want to try and use an object that you cleared. I do remember discussions about making it clear out the vtable, since you _want_ it to blow up after it's been cleared

Re: clear bug?

2011-09-05 Thread Andrej Mitrovic
On 9/6/11, Jonathan M Davis wrote: > Why would you > ever try and use an object that had been cleared? TDPL, that's why. Things might have changed but how would someone new to D know that?

Re: clear bug?

2011-09-05 Thread Jonathan M Davis
On Sunday, September 04, 2011 12:30:58 Dan Olson wrote: > Using dmd 2.054 on osx: > > Calling a instance method after using clear() on an instance is giving > me a bus error. The instance fields look like they are cleared ok, just > can't safely call a method. I think thi

Re: clear bug?

2011-09-05 Thread Bernard Helyer
clear() nulls out the vtable.

Re: clear bug?

2011-09-05 Thread Ali Çehreli
On Sun, 04 Sep 2011 12:30:58 -0700, Dan Olson wrote: > Using dmd 2.054 on osx: > > Calling a instance method after using clear() on an instance is giving > me a bus error. "Segmentation fault" on my Ubuntu. > The instance fields look like they are cleared ok, just >

clear bug?

2011-09-04 Thread Dan Olson
Using dmd 2.054 on osx: Calling a instance method after using clear() on an instance is giving me a bus error. The instance fields look like they are cleared ok, just can't safely call a method. I think this used to work after the object was cleared, and was the reason for clear() ove

Re: Clear big AAs

2011-06-13 Thread bearophile
useo: > toRender is my AA which contains the textures as key (instances of my > class "Texture") and the tiles (position of them) as values. When I > remove the first two lines (clear and set null) it doesn't drops down > to 1 FPS, it runs normal. > > I hope

  1   2   >