[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Hvad koster en malloc og free



Lars Riisgaard Ribe wrote:
Hej sslug-prog’ere.

Jeg sidder og arbejder på noget C-kode, og i den forbindelse har jeg en
funktion, hvor jeg er nødt til at oprette et midlertidigt array af
størrelsen 8-12 floats – oprettelsen (og nedlæggelsen) sker med malloc og
free.


Funktionen kaldes adskillige tusinde gange under program-eksekvering, så jeg
kom pludselig til at tænke på, om jeg kan få hukommelsesfragmentering af
dette, eller om så mange oprettelser og nedlæggelser er en flaskehals?

Er det altid max. 12 floats?


Kan du så ikke bare lave:


#define MAXARRAY 12 ... minfunktion(...) { float lokalarray[MAXARRAY]; ... }

Du kan jo prøve denne løsning og en løsning med
malloc/free og se om det giver nogen forskel i
eksekveringstid/RAM forbrug.

Mogens

--
Mogens Kjaer, Carlsberg A/S, Computer Department
Gamle Carlsberg Vej 10, DK-2500 Valby, Denmark
Phone: +45 33 27 53 25, Fax: +45 33 27 47 08
Email: sslug@sslug Homepage: http://www.crc.dk


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-11-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *