Vai al contenuto


Foto

Memory leak


Questa discussione e' stata archiviata Questo significa che non e' possibile rispondere
40 risposte a questa discussione

#1 monelli

monelli

    Schiavo

  • Membri
  • StellettaStellettaStellettaStelletta
  • 814 Messaggi:

Inviato 07 giugno 2012 - 07:52

Ciao!

Sto programmando roba simil arduino... E ho un problema di memory leak, in quanto, random mi sclerano i cicli for:
se faccio un ciclo per i che va da 0 a 10 magari mi fa 0, 4, 15 ecc :yuno: :yuno: :yuno: :yuno: .
Perchè?????

Sta roba ad esempio può fare casini:

uint8_t *vett=NULL;

vett = (uint8_t*) calloc(N_ANALOG,sizeof(uint8_t));

vett[5]=9;



Dove vett[5] è 8bit mentre il 9 e gli int in generale sono 16bit.

Oppure

void Buffer16(uint16_t value, uint8_t *buff)

{

  uint8_t i=0;   

  for (i=0; i<2; i++)

  {

    buff[i]=value%256;

    value/=256;

  }

  return;

}


Anche qua assegno a buff[i] 8bit un qualcosa che è a 16bit value%256.

Oppure che cacchio può essere??? Ci sto sclerando, poi il bello che non lo fa sempre ma random... :whistler: :whistler:
Help. Grazie

Messaggio modificato da monelli il 07 giugno 2012 - 09:22

Don't drink and drive but smoke and fly.

#2 trallallero

trallallero

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 16.188 Messaggi:

Inviato 07 giugno 2012 - 08:36

Chi ha detto che il 9 è 16 bit ?

Mica hai dichiarato una variabile uint16_t di nome 9, vero ? :asd:

Nella funzione Buffer16 devi castare perché li non hai una costante come 9 ma una variabile da 16 bit che cerchi di mettere in un contenitore da 8 bit.
buff[i] = uint8_t(value % 256);
se non addirittura:
buff[i] = uint8_t(value) % uint8_t(256);
dipende dal compilatore che usi.

Per il resto non ho capito niente.
Don't worry, faith will come soon, like a recall but,
if you can't wait, just stop thinking at all 

 


#3 trallallero

trallallero

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 16.188 Messaggi:

Inviato 07 giugno 2012 - 08:37

E usa il tag code che non si capisce 'na ceppa! :yuno:
Don't worry, faith will come soon, like a recall but,
if you can't wait, just stop thinking at all 

 


#4 norreno

norreno

    Banned

  • Bannati
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 11.039 Messaggi:

Inviato 07 giugno 2012 - 08:41

sono cose come queste che mi hanno portato a rimuovere un linguaggio come il C dalla memoria :v

A kiss was placed / upon my cheek / then all color came back / melting in solid blue tune

~ ..the true memory she left me with is a key to the wine of melancholy... ~ last.fm

Melancholy² ~ Hurry up ~ goodbye ~ ... ~ Nostalgia ~ Broken Birdie Records ~ let's stop the time ~ sleep still ~ happy forever alone ~ my way out ~ springtime

 

 


#5 trallallero

trallallero

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 16.188 Messaggi:

Inviato 07 giugno 2012 - 08:42

sono cose come queste che mi hanno portato a rimuovere un linguaggio come il C dalla memoria :v


Lo so, non è per tutti ma non ti devi vergognare di questo :patpat:
Don't worry, faith will come soon, like a recall but,
if you can't wait, just stop thinking at all 

 


#6 p.nightmare

p.nightmare

    Dittatore

  • Amministratori
  • 97.875 Messaggi:

Inviato 07 giugno 2012 - 08:44

Per il resto non ho capito niente.

ho lollato :asd:

No real limits of any kind apply here - not even the sky
è diventato un tutt'uno con lo spazio...
PVoutput


#7 norreno

norreno

    Banned

  • Bannati
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 11.039 Messaggi:

Inviato 07 giugno 2012 - 08:47

Lo so, non è per tutti ma non ti devi vergognare di questo :patpat:


Piuttosto me ne vanto, è come uscire da matrix :v

comunque ai tempi scrivevo anche in codice assembly, perciò non buttarla sulle capacità mentali, tanto non mi tocca minimamente :v

:v

A kiss was placed / upon my cheek / then all color came back / melting in solid blue tune

~ ..the true memory she left me with is a key to the wine of melancholy... ~ last.fm

Melancholy² ~ Hurry up ~ goodbye ~ ... ~ Nostalgia ~ Broken Birdie Records ~ let's stop the time ~ sleep still ~ happy forever alone ~ my way out ~ springtime

 

 


#8 monelli

monelli

    Schiavo

  • Membri
  • StellettaStellettaStellettaStelletta
  • 814 Messaggi:

Inviato 07 giugno 2012 - 09:26

ho lollato :asd:


Non ho capito...

Per il resto vi ho identato il codice :halone:
Grazie tralallero e ancora una info:
se faccio una printf di un uint8 posso usare %d e non dà problemi giusto?
se faccio una scanf per leggere un numero intero positivo uint8 uso %hd ti quadra?
se faccio una scanf per leggere un numero intero positivo uint32 uso %ld?
Don't drink and drive but smoke and fly.

#9 trallallero

trallallero

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 16.188 Messaggi:

Inviato 07 giugno 2012 - 09:32

Non ho capito...

Per il resto vi ho identato il codice :halone:
Grazie tralallero e ancora una info:
se faccio una printf di un uint8 posso usare %d e non dà problemi giusto?
se faccio una scanf per leggere un numero intero positivo uint8 uso %hd ti quadra?
se faccio una scanf per leggere un numero intero positivo uint32 uso %ld?


Meglio %hd anche per la printf.

scanf Immagine inserita
Don't worry, faith will come soon, like a recall but,
if you can't wait, just stop thinking at all 

 


#10 monelli

monelli

    Schiavo

  • Membri
  • StellettaStellettaStellettaStelletta
  • 814 Messaggi:

Inviato 07 giugno 2012 - 09:37

Cosa hai contro la scanf? poi in verità sono sscanf...
Don't drink and drive but smoke and fly.

#11 trallallero

trallallero

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 16.188 Messaggi:

Inviato 07 giugno 2012 - 09:42

Non puoi controllare la quantità di caratteri digitati dallo user rischiando un overflow, meglio fgets.
Don't worry, faith will come soon, like a recall but,
if you can't wait, just stop thinking at all 

 


#12 trallallero

trallallero

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 16.188 Messaggi:

Inviato 07 giugno 2012 - 09:43

http://www.dwheeler..../dangers-c.html
Don't worry, faith will come soon, like a recall but,
if you can't wait, just stop thinking at all 

 


#13 yorkeiser

yorkeiser

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 68.967 Messaggi:

Inviato 07 giugno 2012 - 09:57

sono cose come queste che mi hanno portato a rimuovere un linguaggio come il C dalla memoria :v


Hai ragione, i Timer del VB6 sono più facili da scrivere :asd:

Il sole è giallo

Brava Giovanna, brava

E canto please don't let me be misunderstood mentre parcheggio nel parcheggio l'alfasud


#14 norreno

norreno

    Banned

  • Bannati
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 11.039 Messaggi:

Inviato 07 giugno 2012 - 09:58

Hai ragione, i Timer del VB6 sono più facili da scrivere :asd:


.. e 2 :asd:


:sofico:

A kiss was placed / upon my cheek / then all color came back / melting in solid blue tune

~ ..the true memory she left me with is a key to the wine of melancholy... ~ last.fm

Melancholy² ~ Hurry up ~ goodbye ~ ... ~ Nostalgia ~ Broken Birdie Records ~ let's stop the time ~ sleep still ~ happy forever alone ~ my way out ~ springtime

 

 


#15 yorkeiser

yorkeiser

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 68.967 Messaggi:

Inviato 07 giugno 2012 - 10:04

Why 2? Al contrario di trolla io parteggio per il VB6, non l'ho mai nascosto

Il sole è giallo

Brava Giovanna, brava

E canto please don't let me be misunderstood mentre parcheggio nel parcheggio l'alfasud


#16 trallallero

trallallero

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 16.188 Messaggi:

Inviato 07 giugno 2012 - 10:09

Ecco, from now it's a language contest.

Ogni linguaggio finché viene usato vuol dire che serve, quando non viene più usato vuol dire che è morto e non serve più.
Non rompete i coglioni.
Don't worry, faith will come soon, like a recall but,
if you can't wait, just stop thinking at all 

 


#17 norreno

norreno

    Banned

  • Bannati
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 11.039 Messaggi:

Inviato 07 giugno 2012 - 10:11

In b4 tigershark

A kiss was placed / upon my cheek / then all color came back / melting in solid blue tune

~ ..the true memory she left me with is a key to the wine of melancholy... ~ last.fm

Melancholy² ~ Hurry up ~ goodbye ~ ... ~ Nostalgia ~ Broken Birdie Records ~ let's stop the time ~ sleep still ~ happy forever alone ~ my way out ~ springtime

 

 


#18 trallallero

trallallero

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 16.188 Messaggi:

Inviato 07 giugno 2012 - 10:17

In b4 tigershark


Il C#, quello in inglese di l'ondon, è il più meglio di tutti! :halone:
Don't worry, faith will come soon, like a recall but,
if you can't wait, just stop thinking at all 

 


#19 norreno

norreno

    Banned

  • Bannati
  • StellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 11.039 Messaggi:

Inviato 07 giugno 2012 - 10:20

:pff:

A kiss was placed / upon my cheek / then all color came back / melting in solid blue tune

~ ..the true memory she left me with is a key to the wine of melancholy... ~ last.fm

Melancholy² ~ Hurry up ~ goodbye ~ ... ~ Nostalgia ~ Broken Birdie Records ~ let's stop the time ~ sleep still ~ happy forever alone ~ my way out ~ springtime

 

 


#20 yorkeiser

yorkeiser

    Schiavo

  • Membri
  • StellettaStellettaStellettaStellettaStellettaStellettaStellettaStelletta
  • 68.967 Messaggi:

Inviato 07 giugno 2012 - 10:36

Ecco, from now it's a language contest.

Ogni linguaggio finché viene usato vuol dire che serve, quando non viene più usato vuol dire che è morto e non serve più.
Non rompete i coglioni.


trolled trollallero :trollface:

Il sole è giallo

Brava Giovanna, brava

E canto please don't let me be misunderstood mentre parcheggio nel parcheggio l'alfasud