Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 12 May 2011 07:01:33 -0500 Message-ID: <4DCBCC1F.41A5@mindspring.com> Date: Thu, 12 May 2011 08:01:35 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Would someone tell me if I'm on the wrong track? References: <70cf2865-5c4a-47a5-a8e8-ac369c2b91b3@k22g2000yqh.googlegroups.com> <4dca2cf0$0$18239$4fafbaef@reader2.news.tin.it> <35d5a07f-b868-4f6e-83fd-e333baba79fc@gu8g2000vbb.googlegroups.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 52 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.223.89 X-Trace: sv3-5oOBJTOk0MIiL1IJBEAaa1MRLKK86o/rRZ6S1YM0BrCxA0qmeKtIP/tqmF4zUZ65HNQ1rEzcHB4z0M8!1U7YUm56CPlBGr+cdI2zG6RljAjrWQuGDqrDFDRagE+InUTIp2EAc5S6Or96bU85ijoMgcWFII/C!NCDV0g05Cw== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2921 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:3798 luser- -droog wrote: > > On May 11, 1:31 am, "io_x" wrote: > > "luser- -droog" ha scritto nel messaggionews:70cf2865-5c4a-47a5-a8e8-ac369c2b91b3@k22g2000yqh.googlegroups.com... > > > > > > > > > I'm trying to build a new memory allocation scheme for > > > my postscript interpreter to satisfy these requirements: > > > % pointer + offset + size + short tag <= 32bits > > > % 'garbage-collection'-ready (structure the heap for easy iteration) > > > % all memory is in one region for easy restore from disk > > > > > So I've written a prototype where the "pointer" is an index > > > into an extendable address table stored in the heap itself. > > > And it seems to work! But I don't trust it, you know? > > > > > I'd appreciate any comments the experts here could offer. > > > [...] > > > /* grow memory by sz */ > > > void growmem(mfile *mem, unsigned sz) { > > > unsigned char *tmp; > > > if (sz < pgsz) sz = pgsz; > > > else sz = (sz/pgsz + 1) * pgsz; > > > > what about if this mult above overflow? > > > > > sz += mem->max; > > > > what about if this sz += overflow? > > i not understand well the remain (too much complex > > for my little think) > > but i think, it is better to see if sz overflow > > and in input to write "if((int) sz <0) return -1;" > > so that each function can fail. > > never exist one function can not fail > > unsigned sz; > (int) sz < 0 > > Does this just check the high bit (assuming 2's complement)? I don't know, but I don't see the relevance of ((int) sz < 0). If you want to check for wrap around after (sz += mem->max), then if (sz - mem->max > sz) ThenItWrapped; -- pete