Skip to content

[Documentation] Custom cpcalloc actually does need to zero memory #250

@nbr0wn

Description

@nbr0wn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions