[PD-dev] Pointers changing/corrupting (used to be "signal nan values")
IOhannes m zmoelnig
zmoelnig at iem.at
Wed Apr 27 13:59:12 CEST 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
some more comments, to fill in the gaps:
On 2011-04-27 13:51, IOhannes m zmoelnig wrote:
> a quick glance at lpcanalysis_tilde_new() reveils, that you are
> allocating data on the stack (which will be freed as soon as you leave
> lpcanalysis_tilde_new()!), store their addresses and re-use them later
> (when the memory is already freed).
which is not a good idea.
instead, you have to allocate on the heap, and manually free once you
don't need the data anymore.
>
> you cannot do:
> <ko>
> void*lpca_new() {
> //...
> t_sample winlis[2088];
> x->win=winlis;
> //...
> }
> </ko>
>
> instead you have to do:
> <ok>
> void lpca_free(x) {
> freebytes(x->win);
which really should read:
freebytes(x->win, 2088*sizeof(t_sample));
> //...
> }
> void*lpca_new() {
> //...
> x->win=getbytes(2088*sizeof(t_sample));
> //...
> }
> </ok>
and of course it would be nice, if 2088 was not hardcoded, but insteadbe
settable; e.g.
<nice>
void lpca_free(x) {
freebytes(x->win, x->winsize*sizeof(t_sample));
//...
}
void*lpca_new() {
//...
x->winsize=2088;
x->win=getbytes(x->winsize*sizeof(t_sample));
//...
}
</nice>
fgmasdr
IOhannes
_______________________________________________
Pd-dev mailing list
Pd-dev at iem.at
http://lists.puredata.info/listinfo/pd-dev
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk24BRAACgkQkX2Xpv6ydvRiZwCguQoy5rXGsBSX+5BRrFssYDOi
EckAoKyLf08ZtXkFWZnraZF2Y9QOnDpP
=1g/W
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3636 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20110427/95b4a645/attachment.bin>
More information about the Pd-dev
mailing list