webengine/osswebengine/MemoryManager/Src/fast_malloc.cpp
changeset 1 7c90e6132015
parent 0 dd21522fd290
child 26 cb62a4f66ebe
equal deleted inserted replaced
0:dd21522fd290 1:7c90e6132015
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 *
       
    17 */
     1 /*
    18 /*
     2   This is a version (aka dlmalloc) of malloc/free/realloc written by
    19   This is a version (aka dlmalloc) of malloc/free/realloc written by
     3   Doug Lea and released to the public domain, as explained at
    20   Doug Lea and released to the public domain, as explained at
     4   http://creativecommons.org/licenses/publicdomain.  Send questions,
    21   http://creativecommons.org/licenses/publicdomain.  Send questions,
     5   comments, complaints, performance data, etc to dl@cs.oswego.edu
    22   comments, complaints, performance data, etc to dl@cs.oswego.edu
  4974     }
  4991     }
  4975 
  4992 
  4976     return oldmark;
  4993     return oldmark;
  4977 }
  4994 }
  4978 
  4995 
       
  4996 #ifdef TRACE_CHUNK_USAGE
       
  4997 void TraceChunkUsage(TInt aChunkHandle, TUint8* aBase, TInt aChunkSize);
       
  4998 #else
       
  4999 #define TraceChunkUsage(a,b,c)
       
  5000 #endif
  4979 void* symbian_mmap(size_t size)
  5001 void* symbian_mmap(size_t size)
  4980 {
  5002 {
  4981     size_t addr = (size_t)watermark;
  5003     size_t addr = (size_t)watermark;
  4982 
  5004 
  4983     if (free_list) {
  5005     if (free_list) {
  5021     if (addr == (size_t)watermark)
  5043     if (addr == (size_t)watermark)
  5022         watermark = (void*)((int)watermark + size);
  5044         watermark = (void*)((int)watermark + size);
  5023     else
  5045     else
  5024         oldmark = (void*)addr;
  5046         oldmark = (void*)addr;
  5025 
  5047 
       
  5048     TraceChunkUsage(rchunk.Handle(),rchunk.Base(),rchunk.Size());
  5026     MEM_LOGF( _L8("chunk size: %d"), rchunk.Size());
  5049     MEM_LOGF( _L8("chunk size: %d"), rchunk.Size());
  5027     return oldmark;
  5050     return oldmark;
  5028 }
  5051 }
  5029 
  5052 
  5030 int symbian_munmap(void* ptr, size_t size)
  5053 int symbian_munmap(void* ptr, size_t size)
  5065                     free(cell);
  5088                     free(cell);
  5066 
  5089 
  5067                     // all three cells are adjacent
  5090                     // all three cells are adjacent
  5068                     if (p->ptr + p->size == e->ptr) {
  5091                     if (p->ptr + p->size == e->ptr) {
  5069                         p->size += e->size;
  5092                         p->size += e->size;
  5070                         p->next = 0;
  5093                         p->next = e->next;
  5071                         free(e);
  5094                         free(e);
  5072                     }
  5095                     }
  5073                 } else if (cell->ptr + cell->size == e->ptr) {
  5096                 } else if (cell->ptr + cell->size == e->ptr) {
  5074                     // adjacent to right cell
  5097                     // adjacent to right cell
  5075                     e->ptr = cell->ptr;
  5098                     e->ptr = cell->ptr;
  5091                 	p->next = cell;	
  5114                 	p->next = cell;	
  5092             }
  5115             }
  5093         }
  5116         }
  5094     }
  5117     }
  5095 
  5118 
       
  5119     TraceChunkUsage(rchunk.Handle(),rchunk.Base(),rchunk.Size());
  5096     MEM_LOGF( _L8("chunk size: %d"), rchunk.Size());
  5120     MEM_LOGF( _L8("chunk size: %d"), rchunk.Size());
  5097     return 0;
  5121     return 0;
  5098 }
  5122 }
  5099 
  5123 
  5100 void log_abort( const char* file, unsigned int line)
  5124 void log_abort( const char* file, unsigned int line)