+---------- On Apr 16, Jason Saunders said:
> Well, it seems the Ns_Cache functions weren't what I was looking for, but I
> have an idea of what might work...

Have you prototyped any of this code to determine whether you even need
to worry about this?  Premature optimization is the root of all evil.

> To ensure locality of the linked lists (of type Y objects), I can allocate a
> stack of 4k or 8k and a stack access mutex as each type X object is created,
> to be used to store the type Y objects associated with the new type X
> object. And then by keeping a pointer to the top of the stack I can then add
> type Y objects to the stack and keep them local to each other.
>
> Then the type X objects could be put in hashes.
>
> How does that sound?

If you're only talking 8K bytes of objects, then I question whether you
really have enough objects to worry about locality of reference. How
many Xs are you talking about?

Furthermore, given such a small number of Ys, you might be better off
storing the Ys in an array, and simply shifting the tail of the array
when you need to insert an element. This will maximize your cache hits
during sequential access (which is probably what you really mean when
you talk about locality).  Whether this is a better approach depends on
the ratio of insertions to accesses.

None of this is worth doing until you have a prototype on which you can
actually measure the performance.

Reply via email to