D - Fastest way to clear an Associative Array?
- Gerd Janssen (10/10) Oct 09 2003 Hi,
- Justin Henzie (22/40) Oct 09 2003 Does dup not work on associative arrays.
- Matthew Wilson (4/14) Oct 09 2003 Clearly, associative arrays should have a clear() method. I'm surprised ...
- Vathix (4/14) Oct 09 2003 I think you only need to set it to null.
- Matthew Wilson (7/28) Oct 09 2003 That's not clearing the aa, that's "deleting" the instance. The two are
Hi, I use an associative array as cache: void clearCache() { char[][] keys = cache.keys; for (int i = 0; i < keys.length; i++) delete cache(keys[i]); } Is there a faster way to clear the cache? Thanks Gerd
Oct 09 2003
Does dup not work on associative arrays. If iy does (I am on my mac), one could create a static associative array (empty) and then assuming cache is an ivar. cache = BasicArray.dup(); or class { char[char[]] cache; void clearCache () { char[char[]] dummyCache; cache = dummyCache; } } this will only work if cache is an ivar, not for arguments passed to methods. or something similiar would seem to be the right approach. Reassigning the reference removes it as a strong root for GC and thus allows the elements to be collected if not referenced elsewhere. Of course I could be absolutely wrong. hope that helps Justin Gerd Janssen wrote:Hi, I use an associative array as cache: void clearCache() { char[][] keys = cache.keys; for (int i = 0; i < keys.length; i++) delete cache(keys[i]); } Is there a faster way to clear the cache? Thanks Gerd
Oct 09 2003
Clearly, associative arrays should have a clear() method. I'm surprised that they don't "Gerd Janssen" <Gerd_member pathlink.com> wrote in message news:bm35la$290l$1 digitaldaemon.com...Hi, I use an associative array as cache: void clearCache() { char[][] keys = cache.keys; for (int i = 0; i < keys.length; i++) delete cache(keys[i]); } Is there a faster way to clear the cache? Thanks Gerd
Oct 09 2003
I think you only need to set it to null. cache = null; "Gerd Janssen" <Gerd_member pathlink.com> wrote in message news:bm35la$290l$1 digitaldaemon.com...Hi, I use an associative array as cache: void clearCache() { char[][] keys = cache.keys; for (int i = 0; i < keys.length; i++) delete cache(keys[i]); } Is there a faster way to clear the cache? Thanks Gerd
Oct 09 2003
That's not clearing the aa, that's "deleting" the instance. The two are separate. It's important, because you may have shared references to the same aa, and wish to empty it. If you delete/replace the instance in one part, all the others will still point to the old, non-empty, instance. "Vathix" <vathix dprogramming.com> wrote in message news:bm4k9f$13jr$1 digitaldaemon.com...I think you only need to set it to null. cache = null; "Gerd Janssen" <Gerd_member pathlink.com> wrote in message news:bm35la$290l$1 digitaldaemon.com...Hi, I use an associative array as cache: void clearCache() { char[][] keys = cache.keys; for (int i = 0; i < keys.length; i++) delete cache(keys[i]); } Is there a faster way to clear the cache? Thanks Gerd
Oct 09 2003