+---------- On Apr 15, Jason Saunders said: > Pete's idea of using the Ns_Cache() functions looks ideal. As I understand > it, when you call Ns_CacheCreateSz(), you specify the maximum size of the > cache that you want and then Ns_CacheMalloc() allocates memory from that > cache. I then have some questions:
No, that's not what Ns_CacheMalloc does. Ns_CacheMalloc allocates memory from a heap owned by the cache, but there is no limit on the size of that heap. A cache tracks its current size based on the size parameter of the Ns_CacheSetValueSz function. You have to use that function to control the size of the cache. > 1. Apart from the limitations of main memory, is there a limit to the number > of caches I can have? Could I have, say, 1000 caches of 8k each? Yes. But there is some overhead for each cache. I don't know exactly what it is, but I wouldn't be surprised if it's on the order of 256 bytes. > 2. Is the memory allocated on executing Ns_CacheCreateSz() contiguous? Ns_CacheCreateSz only allocates a small amount of memory, irrelevant to the size limit you specify for the cache. > 3. Is there a way of deleting a cache once it is no longer needed? In the > online documentation, I can see Ns_CacheDeleteEntry() but that refers to the > cache entries and not the cache itself. Ns_CacheDestroy. > 4. As an alternative to 3, is it possible to re-name a Cache after it has > been created? No.
