Ticket #4118 (closed defect: fixed)

Opened 7 years ago

Last modified 7 years ago

Hash table data structures don't correctly support objects

Reported by: gemacke Owned by: gemacke
Priority: high Milestone: 1.2
Version: 1.1.1 Severity: normal
Keywords: Cc:

Description (last modified by gemacke) (diff)

The hash table structures don't currently call destructors when elements are removed from the table. This is incorrect behavior when the elements are objects.

They also initialize memory a bit inefficiently. Currently, they call new to initialize the value_type array. Instead, they should use malloc, and then construct the memory when inserting.

Here is how it should work:

  1. Memory for the value_type array should be allocated with malloc.
  2. At element insertion, we should use placement new to copy the element to its location in the value_type array. This will construct an object correctly.
  3. At element deletion, we should call the destructor of the element. This is necessary for objects. Note that all the existing elements should have their destructors called in the hash structure's destructor.
  4. When moving existing elements, such as for resize(), we should not do any construction / destruction. The memory should just be copied.

The following structures need to be updated:

  • xmt_hash_table
  • xmt_hash_set
  • hachar

Change History

comment:1 Changed 7 years ago by gemacke

  • Status changed from new to accepted

comment:2 Changed 7 years ago by gemacke

  • Description modified (diff)

comment:3 Changed 7 years ago by gemacke

  • Description modified (diff)

comment:4 Changed 7 years ago by gemacke

Addressed for xmt_hash_table in r3763.

comment:5 Changed 7 years ago by gemacke

Addressed for xmt_hash_set in r3765.

comment:6 Changed 7 years ago by gemacke

  • Status changed from accepted to closed
  • Resolution set to fixed

Addressed for hachar in r3766.

Note: See TracTickets for help on using tickets.