Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c Subject: Re: Malloc Query Date: Sat, 21 May 2011 14:30:39 +1200 Lines: 48 Message-ID: <93omefF1bbU15@mid.individual.net> References: <87aael3xw1.fsf@blp.benpfaff.org> <0.9e954b297cf63735a997.20110518193428BST.87zkmjuabv.fsf@bsb.me.uk> <0.3ac369f64d11bcd06d18.20110519002615BST.87ei3vtwtk.fsf@bsb.me.uk> <98a074c87051012-452fb@gmail.com> <0.bf5e9ff46dfbfc1e78d6.20110519032218BST.87tycrsa3p.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net eZwLtOeJSAw+8KorKsla/QspbYcQYb1TTW9y64w1fLbsR+5vaS Cancel-Lock: sha1:h7Fp7wuNMIj5QViHzaAGnYpjJOI= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:4484 On 05/20/11 10:34 AM, Uncle Steve wrote: A couple of comments on the code: > arena_head * arena_creat(size_t s, int n) > { > arena_head * h; > int i; > > h = malloc(sizeof(arena_head)); > if(h == NULL) { > perror("malloc()"); > exit(1); > } > > h->obj_size = s; > h->arena_size = n; > h->free = n; > > h->arena = malloc(s * n); > if(h->arena == NULL) { > perror("malloc()"); > exit(1); > } > > h->free_list = 0; > > for(i = 0; i< n; i++) > *((int *) arena_obj_addr(h, i)) = i + 1; > > *((int *) arena_obj_addr(h, i)) = -1; This writes past the end of the allocated block. > return(h); > } > > > typedef unsigned long long int T64; > > #define processcputime(p) \ Why go the the trouble of declaring this as a messy macro? -- Ian Collins