Python/C - Memory-Management

Heiko Wolf heiko.wolf at dlr.de
Thu Mar 7 04:54:46 EST 2002


Hi there,

I've got some C-functions that shall be adressed from Python. Thats no
problem, thanks to SWIG.

But now there is a problem about the memory management: One of the
C-functions allocates memory for all the other functions. In C it
works that way:

static char *memory = NULL;

int init_mem (void)
{

memory = (char *)malloc(sizeof(char) * 1000);
}

int free_mem (void)
{

free(memory);
}

If another function calls init_mem, it can use memory until free_mem
is called... I want to do the same now in Python, but it seems as if
the static memory isnt kept somewhere? When I try accessing it, I get
a Segmentation Fault... Any suggestions?

Cheers, Heiko



More information about the Python-list mailing list