RE: memory allocation in GLIB
- From: martyn 2 russell bt com
- To: hopeye cfl rr com, gtk-app-devel-list gnome org
- Subject: RE: memory allocation in GLIB
- Date: Mon, 10 Mar 2003 16:01:26 -0000
I have a problem (SEGFAULT) when freeing a vector allocated using
routines in GLIB (version 1.2.10).
I declare my variable as:
gfloat *vector;
Just as a word of advise, it is usually best to initialise pointers to NULL
and check for NULL before you free them, and generally, when I have free'd a
pointer, I set it to NULL afterwards. This way I should never get into a
situation where I am freeing memory already free'd and I know if it is being
used based on the pointers value.
Just makes me cringe when I see unintialised pointers :S
:)
I then allocate memory as:
vector = g_malloc ( (some_int)*sizeof(gfloat) );
This allows me to access the memory using:
for (i=0; i<(some_int); i++) vector[i] = some_float;
then when exiting the function, I free the memory using:
g_free( vector );
This statement causes a SEGFAULT. Can anyone suggest what I am doing
wrong.
Also, what does a back trace report from gdb?
Regards,
Martyn
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]