atom feed61 messages in at.iem.pd-listRe: [PD] fux_kinect
FromSent OnAttachments
sonia yuditskayaOct 25, 2011 6:07 pm 
sonia yuditskayaOct 25, 2011 6:13 pm 
vadeOct 25, 2011 7:00 pm 
Hans-Christoph SteinerOct 25, 2011 8:21 pm 
sonia yuditskayaOct 26, 2011 2:07 pm 
Hans-Christoph SteinerOct 26, 2011 2:54 pm 
sonia yuditskayaOct 26, 2011 3:27 pm 
Budi PrakosaOct 26, 2011 5:25 pm 
Hans-Christoph SteinerOct 26, 2011 6:00 pm 
Hans-Christoph SteinerOct 26, 2011 7:25 pm.patch, .patch
Budi PrakosaOct 26, 2011 7:49 pm 
Hans-Christoph SteinerOct 26, 2011 7:54 pm 
Budi PrakosaOct 26, 2011 10:23 pm 
Jordi SalaOct 27, 2011 4:39 am 
Budi PrakosaOct 27, 2011 4:50 am 
José Luis Santorcuato TapiaNov 11, 2011 4:19 am 
Hans-Christoph SteinerNov 11, 2011 7:30 am 
tim vetsNov 11, 2011 7:57 am 
Hans-Christoph SteinerNov 11, 2011 8:02 am 
tim vetsNov 11, 2011 8:06 am 
Mathieu BouchardNov 11, 2011 8:38 am 
tim vetsNov 11, 2011 8:55 am 
Hans-Christoph SteinerNov 11, 2011 9:10 am 
Mathieu BouchardNov 11, 2011 10:42 am 
tim vetsNov 11, 2011 10:49 am 
tim vetsNov 11, 2011 10:52 am 
tim vetsNov 11, 2011 11:04 am 
tim vetsNov 11, 2011 11:18 am 
tim vetsNov 11, 2011 11:24 am 
Hans-Christoph SteinerNov 11, 2011 12:25 pm 
Mathieu BouchardNov 11, 2011 12:25 pm 
tim vetsNov 11, 2011 12:54 pm.Other
tim vetsNov 11, 2011 12:58 pm 
Mathieu BouchardNov 12, 2011 8:53 am 
Mathieu BouchardNov 12, 2011 8:55 am 
Mathieu BouchardNov 12, 2011 9:01 am 
Mathieu BouchardNov 12, 2011 9:11 am 
Claude Heiland-AllenNov 12, 2011 9:13 am 
Mathieu BouchardNov 12, 2011 9:15 am 
tim vetsNov 12, 2011 9:19 am 
Mathieu BouchardNov 12, 2011 9:30 am 
Mathieu BouchardNov 12, 2011 9:33 am 
tim vetsNov 12, 2011 9:55 am 
tim vetsNov 12, 2011 9:58 am 
Mathieu BouchardNov 12, 2011 10:04 am 
tim vetsNov 12, 2011 10:08 am 
tim vetsNov 12, 2011 10:10 am.Other
tim vetsNov 14, 2011 5:44 am.txt
tim vetsNov 14, 2011 6:41 am 
Mathieu BouchardNov 14, 2011 7:53 am 
Budi PrakosaNov 14, 2011 9:03 am 
tim vetsNov 14, 2011 10:19 am 
Matthias KronlachnerNov 14, 2011 5:07 pm 
tim vetsNov 15, 2011 6:23 am 
tim vetsNov 15, 2011 7:11 am 
Mathieu BouchardNov 15, 2011 7:12 am 
Mathieu BouchardNov 15, 2011 7:14 am 
Matthias KronlachnerNov 15, 2011 11:26 am 
Budi PrakosaNov 21, 2011 9:24 pm 
Mathieu BouchardNov 22, 2011 7:18 am 
Budi PrakosaNov 22, 2011 4:03 pm 
Subject:Re: [PD] fux_kinect
From:Mathieu Bouchard (mat@artengine.ca)
Date:Nov 12, 2011 9:30:44 am
List:at.iem.pd-list

Le 2011-11-12 à 17:13:00, Claude Heiland-Allen a écrit :

A nice idiom for malloc is to use the sizeof of the target of the pointer to which you are assigning its result (no explicit cast needed when assigning from a void * afaik, at least no warnings/errors here with gcc (Debian 4.4.5-8) 4.4.5): struct foo *f = malloc(sizeof(*f));

1. This does not work in C++ because implicit casts from void* are all assumed to be mistakes ;

2. In any case, this requires that you did type f in the malloc. The problem we have here is because the wrong type name was typed in a sizeof. If a wrong type name can be typed there, so can a wrong variable name.

Therefore, either use «operator new», or if you're stuck with C, use a macro that does the job for you :

#define NEW(T) ((T*)malloc(sizeof(T)))

so that if you do a wrong assignment, you will get an error for it :

struct foo *e = NEW(foo); struct foo *f = NEW(typeof(*f)); struct bar *g = NEW(foo); // wrong struct bar *h = NEW(typeof(*f)); // wrong

error: cannot convert ‘foo*’ to ‘bar*’ in initialization error: cannot convert ‘foo*’ to ‘bar*’ in initialization

But anyway, those mallocs in [fux_kinect] are superfluous because you can reserve that amount of RAM directly in fux_kinect by removing the «*».

That goes for nearly any struct that you need to create at the same time as another struct, and destroy at the same time as that same struct, and never need to change the size of. In order to do that, you need to be able to init and finalise separately from malloc/free. That's why the function is named pthread_cond_init and not pthread_cond_new, for example.