tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Semantics of copying mutex/rwlock
On Wed, 16 Jun 2010 13:21:49 -0400 (EDT)
der Mouse <mouse%Rodents-Montreal.ORG@localhost> wrote:
> > OK I wrote a simple benchmark. It turns out malloc() is quite
> > expensive, it's about 6 times slower to call malloc() for each
> > mutex, compared to init/destroy pair.
>
> (a) But you need to malloc only the new mutexes, whereas you need to
> destroy/init all, including the old ones. Or do you mean you profiled
> actual use and found this difference between the two paradigms?
>
I timed malloc() for 1000 mutex objects.
Then I timed 2x init() + 2x destroy() mutex calls for 1000 mutex
objects.
The time for malloc run was 6 times longer. So eventually the time
difference will probably level off, but it'll start happening after I
increase the number of mutex objects quite a few times.
Actually I've decided on the optimal solution:
1) malloc() not individual mutex objects, but arrays of objects. Join
allocations into a linked list.
2) Have a single array of pointers to mutex objects. Every time you
need to grow it, just call realloc() and set mutex pointers.
[12345678]->[12345678]->NULL /* linked list of arrays with 8 objects */
[^^^^^^^ ^^^^^^^^] /* main array of pointers to mutex objects */
Home |
Main Index |
Thread Index |
Old Index