I have a data structure with a symbol and an array of symbols that store array names defined as:
``` t_symbol **x_weights_arrays; t_symbol *x_biases_array; ```
When I'm done with them, I want to free the memory, but calling free(x_biases_array) doesn't seem to work, and once called, as soon as I try to do something else in Pd (like unlock the patch and choose an object), Pd crashes.
I have narrowed down the error to freeing these symbols, and I'm sure the crash is not caused by something else. I scanned m_pd.h to see if there is a function to free t_symbol memory, but didn't seem to find anything. This might be something obvious for C-savvy people, but I'm not one, so any advice is welcome.
hi,
free(x_biases_array) doesn't seem to work
i'm not to good at C but you are missing the correct path ("nameofthestruct"->"nameofthevarible"). like
free(x->x_biases_array).
--
Mensaje telepatico asistido por maquinas.
On 22/02/2024 06:19, Alexandros Drymonitis wrote:
I have a data structure with a symbol and an array of symbols that store array names defined as:
t_symbol **x_weights_arrays; t_symbol *x_biases_array;
When I'm done with them, I want to free the memory, but calling free(x_biases_array) doesn't seem to work, and once called, as soon as I try to do something else in Pd (like unlock the patch and choose an object), Pd crashes.
I have narrowed down the error to freeing these symbols, and I'm sure the crash is not caused by something else. I scanned m_pd.h to see if there is a function to free t_symbol memory, but didn't seem to find anything. This might be something obvious for C-savvy people, but I'm not one, so any advice is welcome.
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
On 2/22/24 14:45, Lucas Cordiviola wrote:
hi,
free(x_biases_array) doesn't seem to work
i'm not to good at C but you are missing the correct path ("nameofthestruct"->"nameofthevarible"). like
free(x->x_biases_array).
Yeah, that's a typo in the email, it's not in the code though. Thanks for pointing it out.
Hi,
Pd symbols are immutable and permanent. `gensym("foo")` looks if the symbol "foo" already exists; if yes, it just returns it, otherwise it creates a new symbol, adds it to the global symbol table and finally returns it.
You must never attempt to free a symbol!
t_symbol **x_weights_arrays; t_symbol *x_biases_array;
Here you must only free `x_weights_array`, which is an array of `t_symbol*`, but not the `t_symbol*` elements themselves.
---
Side note: since symbols are unique and persistent, they can be compared *by address*. In other words, two symbols are equal if they have the same address. This is different from ordinary C-strings which may reside at different memory locations and thus need to be compared with `strcmp()` (or equivalent functions).
Christof
On 22.02.2024 10:19, Alexandros Drymonitis wrote:
I have a data structure with a symbol and an array of symbols that store array names defined as:
t_symbol **x_weights_arrays; t_symbol *x_biases_array;
When I'm done with them, I want to free the memory, but calling free(x_biases_array) doesn't seem to work, and once called, as soon as I try to do something else in Pd (like unlock the patch and choose an object), Pd crashes.
I have narrowed down the error to freeing these symbols, and I'm sure the crash is not caused by something else. I scanned m_pd.h to see if there is a function to free t_symbol memory, but didn't seem to find anything. This might be something obvious for C-savvy people, but I'm not one, so any advice is welcome.
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
This is by far the best explanation of symbols I’ve read, ever.
Thanks!
On 22 Feb 2024, at 13:41, Christof Ressi info@christofressi.com wrote:
Hi,
Pd symbols are immutable and permanent. `gensym("foo")` looks if the symbol "foo" already exists; if yes, it just returns it, otherwise it creates a new symbol, adds it to the global symbol table and finally returns it.
You must never attempt to free a symbol!
t_symbol **x_weights_arrays; t_symbol *x_biases_array;
Here you must only free `x_weights_array`, which is an array of `t_symbol*`, but not the `t_symbol*` elements themselves.
Side note: since symbols are unique and persistent, they can be compared *by address*. In other words, two symbols are equal if they have the same address. This is different from ordinary C-strings which may reside at different memory locations and thus need to be compared with `strcmp()` (or equivalent functions).
Christof
On 22.02.2024 10:19, Alexandros Drymonitis wrote:
I have a data structure with a symbol and an array of symbols that store array names defined as:
t_symbol **x_weights_arrays; t_symbol *x_biases_array;
When I'm done with them, I want to free the memory, but calling free(x_biases_array) doesn't seem to work, and once called, as soon as I try to do something else in Pd (like unlock the patch and choose an object), Pd crashes.
I have narrowed down the error to freeing these symbols, and I'm sure the crash is not caused by something else. I scanned m_pd.h to see if there is a function to free t_symbol memory, but didn't seem to find anything. This might be something obvious for C-savvy people, but I'm not one, so any advice is welcome.
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
Thanks :-D
BTW, Symbols in sclang work the same way. Also, they are frequently used in scripting languages. In this context, this is also referred to as "string interning", see https://en.wikipedia.org/wiki/String_interning
Christof
On 22.02.2024 15:38, Pierre Alexandre Tremblay wrote:
This is by far the best explanation of symbols I’ve read, ever.
Thanks!
On 22 Feb 2024, at 13:41, Christof Ressi info@christofressi.com wrote:
Hi,
Pd symbols are immutable and permanent. `gensym("foo")` looks if the symbol "foo" already exists; if yes, it just returns it, otherwise it creates a new symbol, adds it to the global symbol table and finally returns it.
You must never attempt to free a symbol!
t_symbol **x_weights_arrays; t_symbol *x_biases_array;
Here you must only free `x_weights_array`, which is an array of `t_symbol*`, but not the `t_symbol*` elements themselves.
Side note: since symbols are unique and persistent, they can be compared *by address*. In other words, two symbols are equal if they have the same address. This is different from ordinary C-strings which may reside at different memory locations and thus need to be compared with `strcmp()` (or equivalent functions).
Christof
On 22.02.2024 10:19, Alexandros Drymonitis wrote:
I have a data structure with a symbol and an array of symbols that store array names defined as:
t_symbol **x_weights_arrays; t_symbol *x_biases_array;
When I'm done with them, I want to free the memory, but calling free(x_biases_array) doesn't seem to work, and once called, as soon as I try to do something else in Pd (like unlock the patch and choose an object), Pd crashes.
I have narrowed down the error to freeing these symbols, and I'm sure the crash is not caused by something else. I scanned m_pd.h to see if there is a function to free t_symbol memory, but didn't seem to find anything. This might be something obvious for C-savvy people, but I'm not one, so any advice is welcome.
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
Em qui., 22 de fev. de 2024 às 11:26, Christof Ressi info@christofressi.com escreveu:
You must never attempt to free a symbol!
poor symbols, trapped forever
Am 22. Februar 2024 10:19:27 MEZ schrieb Alexandros Drymonitis adrcki@gmail.com:
I have a data structure with a symbol and an array of symbols that store array names defined as:
t_symbol **x_weights_arrays; t_symbol *x_biases_array;
When I'm done with them, I want to free the memory, but calling free(x_biases_array) doesn't seem to work, and once called, as soon as I try to do something else in Pd (like unlock the patch and choose an object), Pd crashes.
Never free symbols. A symbol is created by `gensym` and owned by Pd.
mfg.sfg.jfd IOhannes