I've done what you asked. I avoided the extra level of pointers and there's a new array now that contains indexes of free slots in the handle table. Creating and closing handles is now done in constant complexity (and reallocation on the other hand is linear). Commit line changed as per Andre's suggestion and critical sections are tighter. Patch attached.