projects
/
tedtools.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
256c886
)
Optimize mcrealloc
author
teodor
<teodor>
Tue, 22 Nov 2005 16:07:28 +0000
(16:07 +0000)
committer
teodor
<teodor>
Tue, 22 Nov 2005 16:07:28 +0000
(16:07 +0000)
memtest.c
patch
|
blob
|
history
tmalloc.c
patch
|
blob
|
history
diff --git
a/memtest.c
b/memtest.c
index
7db7813
..
9abf087
100644
(file)
--- a/
memtest.c
+++ b/
memtest.c
@@
-118,7
+118,7
@@
main(int argn, char *argv[]) {
printf("mixed:%s free:%d\n", ptr, base->chunk->freesize);
ptr = mcrealloc(ptr1, 120);
printf("mixed:%s free:%d\n", ptr, base->chunk->freesize);
ptr = mcrealloc(ptr1, 120);
- tassert( ptr
<
ptr1 );
+ tassert( ptr
==
ptr1 );
printf("mixed:%s free:%d\n", ptr, base->chunk->freesize);
ptr1 = mcalloc(base, CNTXCHUNK);
printf("mixed:%s free:%d\n", ptr, base->chunk->freesize);
ptr1 = mcalloc(base, CNTXCHUNK);
diff --git
a/tmalloc.c
b/tmalloc.c
index
fee18cb
..
9f96ab9
100644
(file)
--- a/
tmalloc.c
+++ b/
tmalloc.c
@@
-188,10
+188,10
@@
mcalloc(MemoryContext *cntx, size_t size) {
chunk = newchunk;
}
chunk = newchunk;
}
- chunk->freesize -= size;
- alloc = (MCAllocatedSpace*)( chunk->data + chunk->freesize );
+ alloc = (MCAllocatedSpace*)( chunk->data + chunk->size - chunk->freesize );
alloc->size = size;
alloc->cntx = cntx;
alloc->size = size;
alloc->cntx = cntx;
+ chunk->freesize -= size;
if ( cntx->flags & MC_DEBUG ) {
*(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) = MCMAGICKNUMBER;
if ( cntx->flags & MC_DEBUG ) {
*(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) = MCMAGICKNUMBER;
@@
-223,14
+223,12
@@
mcrealloc(void * ptr, size_t size) {
realsize = alloc->size - MCASHDRSZ;
if ( size > realsize ) {
realsize = alloc->size - MCASHDRSZ;
if ( size > realsize ) {
- if ( (char*)alloc == alloc->cntx->chunk->data + alloc->cntx->chunk->freesize &&
+ MemoryChunk *chunk = alloc->cntx->chunk;
+ if ( (char*)alloc == chunk->data + chunk->size - chunk->freesize - alloc->size &&
PTRALIGN(size)-realsize <= alloc->cntx->chunk->freesize ) {
/* just enlarge */
alloc->cntx->chunk->freesize -= PTRALIGN(size)-realsize;
alloc->size+=PTRALIGN(size)-realsize;
PTRALIGN(size)-realsize <= alloc->cntx->chunk->freesize ) {
/* just enlarge */
alloc->cntx->chunk->freesize -= PTRALIGN(size)-realsize;
alloc->size+=PTRALIGN(size)-realsize;
- memmove( ((char*)alloc) - (PTRALIGN(size)-realsize), alloc, PTRALIGN(size)+MCASHDRSZ );
- alloc = (MCAllocatedSpace*) ( ((char*)alloc) - (PTRALIGN(size)-realsize) );
- ptr = (void*)alloc->data;
if ( alloc->cntx->flags & MC_DEBUG ) {
memset( (char*)(alloc->data) + realsize, 0xc3, PTRALIGN(size)-realsize );
*(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) = MCMAGICKNUMBER;
if ( alloc->cntx->flags & MC_DEBUG ) {
memset( (char*)(alloc->data) + realsize, 0xc3, PTRALIGN(size)-realsize );
*(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) = MCMAGICKNUMBER;
@@
-251,6
+249,7
@@
mcrealloc(void * ptr, size_t size) {
void
mcfree(void * ptr) {
MCAllocatedSpace *alloc = (MCAllocatedSpace*)( (char*)ptr - MCASHDRSZ );
void
mcfree(void * ptr) {
MCAllocatedSpace *alloc = (MCAllocatedSpace*)( (char*)ptr - MCASHDRSZ );
+ MemoryChunk *chunk;
if ( ptr==NULL )
tlog(TL_CRIT|TL_EXIT, "mcfree: free null pointer");
if ( ptr==NULL )
tlog(TL_CRIT|TL_EXIT, "mcfree: free null pointer");
@@
-258,7
+257,8
@@
mcfree(void * ptr) {
if ( alloc->cntx->flags & MC_DEBUG )
tassert( *(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) == MCMAGICKNUMBER );
if ( alloc->cntx->flags & MC_DEBUG )
tassert( *(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) == MCMAGICKNUMBER );
- if ( (char*)alloc == alloc->cntx->chunk->data + alloc->cntx->chunk->freesize ) /* last allocated value */
+ chunk = alloc->cntx->chunk;
+ if ( (char*)alloc == chunk->data + chunk->size - chunk->freesize - alloc->size ) /* last allocated value */
alloc->cntx->chunk->freesize+=alloc->size;
alloc->cntx=NULL;
alloc->cntx->chunk->freesize+=alloc->size;
alloc->cntx=NULL;