Skip to content

Commit 8b90755

Browse files
author
Brent Burley
committed
Use placement new for PtexHashMap TableHeader and Entry objects
Placement new is required by C++ to see objects allocated with malloc as objects and not just raw memory. Doing so allows the compiler to properly analyze object lifetimes and usage. Without the placement new, and with dead code / dead store elimination enabled, an unexplained crash was occuring with GCC 15 when running the regression tests. With this change, the crash no longer appears.
1 parent 0653655 commit 8b90755

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/ptex/PtexHashMap.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,14 @@ class PtexHashMap
264264
memsize = sizeof(TableHeader) + sizeof(Entry) * numEntries;
265265
void* table = malloc(memsize);
266266
memset(table, 0, memsize);
267-
TableHeader* header = (TableHeader*) table;
267+
TableHeader* header = new (table) TableHeader;
268268
header->numEntries = numEntries;
269269
header->size = 0;
270+
Entry* entries = (Entry*)((char*)table + sizeof(TableHeader));
271+
for (int32_t i = 0; i < numEntries; ++i)
272+
{
273+
new (&entries[i]) Entry();
274+
}
270275
return table;
271276
}
272277

0 commit comments

Comments
 (0)