In "Memory management the Chipmunk Way", there is a section which reads:
cpSpaceAlloc() – Allocates but does not initialize a cpSpace struct. All allocation functions look more or less like this: return (cpSpace *)cpcalloc(1, sizeof(cpSpace)); You can write your own allocation functions if you want. It is not a requirement that the memory be zeroed.
..turns out if you don't zero the memory, you can fail on an assert in cSpatialIndexInit() - cSpacialIndex.c line 41:
cpAssertHard(!staticIndex->dynamicIndex, "This static index is already associated with a dynamic index.");
... because the dynamicIndex pointer contains whatever garbage was in memory at alloc time.
In "Memory management the Chipmunk Way", there is a section which reads:
cpSpaceAlloc() – Allocates but does not initialize a cpSpace struct. All allocation functions look more or less like this: return (cpSpace *)cpcalloc(1, sizeof(cpSpace)); You can write your own allocation functions if you want. It is not a requirement that the memory be zeroed.
..turns out if you don't zero the memory, you can fail on an assert in cSpatialIndexInit() - cSpacialIndex.c line 41:
cpAssertHard(!staticIndex->dynamicIndex, "This static index is already associated with a dynamic index.");
... because the dynamicIndex pointer contains whatever garbage was in memory at alloc time.