Path: csiph.com!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: Open letter to Ian Collins Date: Sun, 27 May 2012 15:16:15 +1200 Lines: 42 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net PRf9cDQgjlHC/qY/zGPQ2ARqFaku9Toe1BvHiNzjyh2qFekpjvvhXskj2dL37ksMRp Cancel-Lock: sha1:TxXuUzIB2VEXQGn7NK3sBauVWzM= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:12.0) Gecko/20120423 Thunderbird/12.0 In-Reply-To: Xref: csiph.com comp.lang.c:21393 On 05/27/12 10:22 AM, jacob navia wrote: > Hi Ian > > In the c++ newsgroup you asked me for an example of the ccl performance > It was something with building a huge list, then sorting it, if I > remember correctly... > > I have built this example code: > I get a segv when I run the example. Running in dbx with access checking enabled shows: Write to unallocated (wua): Attempting to write 1 byte at address 0x8091d88 which is just past heap block of size 800 bytes at 0x8091a68 This block was allocated from: newHeapObject<-NewLink<-Add_nd<-Add<-main Location of error: heap.c, line 75, newHeapObject() The offending code appears to be here in heap.c: /* The array of block pointers is full. Allocate CHUNK_SIZE blocks more */ siz = (l->BlockCount+CHUNK_SIZE)*sizeof(ListElement *); result = l->Allocator->realloc(l->Heap,siz); if (result == NULL) { return NULL; } l->MemoryUsed+= siz; l->Heap = (char **)result; /* Position pointer at the start of the new area */ result += l->BlockCount*sizeof(ListElement *); /* Zero the new pointers */ memset(result,0,siz); It looks like you are allocating siz byes, incrementing part (half) way through the bock then zeroing the next siz bytes. -- Ian Collins