AW: C - lokalis tomb, vagy pointer+malloc

WLC02E, wlc02e at automation.siemens.com
Mon Jan 23 11:06:09 CET 2006


 Szia,

free-vel felszabaditom a heapen elfoglalt teruletet, nem?

De tegyuk fel, hogy,a fragmentalodas, stb miatt kizazom a malloc-free megoldast, akkor hogyan adok vissza nagyobb tomboket a hivo fuggvenynek? Marad fix tomb a hivo fuggvenyben es a fuggvenyargumentumon keresztuli parameteratadas? Igy viszont adott esetben sokkal tovabb (amig fut a hivo fv.) foglalom a memoriat a nagy meretu tomb szamara, vagy atadom a hivott fuggvenyen belul lokalisan generalt majd megszuntetett tomb cimet es remelem, hogy nem irkal bele egy megszakitas sem, amig feldolgozom? :-))

Koszonom!

Zoli

> -----Ursprüngliche Nachricht-----
> Von: Rancz Lajos csiga at fosch.com 


> Sima C-ben (ahol nincs garbage collector) a függvény futása után nem 
> szabadulnak fel a dinamikusan foglalt memória területek!!! A másik fő 
> különbség, hogy a lokális változók a stackbena vannak, a dinamikusak 
> pedig a heapen. Sokáig futó rendszerben (eg. beágyazott) nem 
> ajánlatos 
> dinamikusan memóriát használni, pl. MISRA nem is engedi. IAR 
> doksi szerint: "For each allocated memory block, a few bytes of data for 
> administrative purposes is required. For applications that allocate a large 
> number of small blocks, this administrative overhead can be substantial. There is 
> also the matter of fragmentation; this means a heap where small sections 
> of free memory is separated by memory used by allocated objects. It is 
> not possible to allocate a new object if there is no piece of free 
> memory that is large enough for the object, even though the sum of the 
> sizes of the free memory exceeds the size of the object. Unfortunately, 
> fragmentation tends to increase as memory is allocated and released. 
> Hence, applications that are designed to run for a long time should try 
> to avoid using memory allocated on the heap."
> 
> Szóval a malloc-kal vigyázni kell.
> 
> Üdv,
> Lajos




More information about the Elektro mailing list