2008/8/15 Hans Leidekker <[EMAIL PROTECTED]>: > > +HINTERNET alloc_handle( object_header_t *hdr ) > +{ > + object_header_t **p; > + ULONG_PTR handle = 0, num; > + > + list_init( &hdr->children ); > + > + EnterCriticalSection( &handle_cs ); > + if (!max_handles) > + { > + num = HANDLE_CHUNK_SIZE; > + if (!(p = heap_alloc_zero( sizeof(ULONG_PTR) * num ))) goto end; > + handles = p; > + max_handles = num; > + } > + if (max_handles == next_handle) > + { > + num = max_handles + HANDLE_CHUNK_SIZE; > + if (!(p = heap_realloc_zero( handles, sizeof(ULONG_PTR) * num ))) > goto end; > + handles = p; > + max_handles = num; > + } > + handle = next_handle; > + if (handles[handle]) ERR("handle isn't free but should be\n"); > + > + handles[handle] = addref_object( hdr ); > + while (handles[next_handle] && (next_handle < max_handles)) > next_handle++; > + > +end: > + LeaveCriticalSection( &handle_cs ); > + return hdr->handle = (HINTERNET)(handle + 1); > +}
Not necessarily wrong, but the common way to implement tables like this is to grow the table by some percentage of the original size, and keep a list of free handles.