Heap management

V13 v13 at priest.com
Fri Oct 27 14:17:36 EEST 2006


On Friday 27 October 2006 11:00, Christos Ricudis wrote:
> Standard malloc() behaviour. H malloc (den kserw ti ginetai sthn C++,
> alla ypo8etw oti h new sthn ousia th malloc() kalei)
> mporei na desmeysei mnhmh, alla h free() den einai pote ypoxrewmenh na
> thn epistrepsei sto leitourgiko systhma, kai prepei na ypo8eseis oti DEN
> to kanei.

  Apo th glibc 2.3 kai meta h malloc() epistrefei mnimi me mmap() 
sto /dev/zero. Ayto exei san apotelesma h mnhmh ayti na ginetai pragmatika 
free otan einai pia eleytheri. (To documentation leei oti ayto ginetai 
sigoyra mono gia megala blocks, alla ap'oti exo dei to kanei kai gia mikra. 
Isos to kanei emesa zitontas mnimi gia ton eayto ths meso ths mmap())

  To programa poy yparxei sto telos se emena ftanei na troei peripoy 13MB 
mnimi kai molis ginei free() h malloc()ed mnimi peytei sta 3MB peripoy.

> H "unix-correct" lysh sto problhma sou, legetai fork(). Exeis ena parent
> process, to opoio phrouniazei paidia. Ka8e paidi anoigei ena
> proka8orismeno ari8mo sockets, kanei th douleia tou kai ystera
> termatizei. Ry8mizeis ton proka8orismeno ari8mo sockets symfwna me to
> tradeoff pou 8eleis metaksy tou memory usage kai tou performance ovehead
> logw ths fork.

  Gia to sygkekrimeno problima to kritirio prepei na'nai ta max paralila open 
sockets per children kai oxi to syonolo ton sockets poy tha anoikseis. Apo 
tin allh bebaia, kathorizontas ena max ttl antimetopizeis pithana memory 
flows...

> Christos Ricudis				ricudis at itc.auth.gr
<<V13>>

------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define SZ      100000
#define BLKSZ   100

int main()
{
        int     n;
        char    *ptr[SZ];

        fprintf(stderr, "Started...\n");
        for (n=0; n<SZ; n++)
        {
                ptr[n]=(char *)malloc(BLKSZ);
                *((ptr[n])+50)='a';
        }

        fprintf(stderr, "Malloced...\n");
        sleep(5);

        fprintf(stderr, "Freeing...\n");
        for (n=0; n<SZ; n++)
                free(ptr[n]);
        fprintf(stderr, "Freeed...\n");

        sleep(5);
        fprintf(stderr, "The end...\n");
}
------------------




More information about the Linux-greek-users mailing list