diff options
author | dgp <dgp@users.sourceforge.net> | 2007-07-01 17:31:20 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2007-07-01 17:31:20 (GMT) |
commit | b7b7a76f55e9cf3a0233401d12077c2a4c02fb58 (patch) | |
tree | d4026023af8a692acd7041d3afcf6c32c771d3ce /generic/tclAlloc.c | |
parent | d4a8765b8fddb5229749b15cac181af631f9e3a6 (diff) | |
download | tcl-b7b7a76f55e9cf3a0233401d12077c2a4c02fb58.zip tcl-b7b7a76f55e9cf3a0233401d12077c2a4c02fb58.tar.gz tcl-b7b7a76f55e9cf3a0233401d12077c2a4c02fb58.tar.bz2 |
merge updates from HEAD
Diffstat (limited to 'generic/tclAlloc.c')
-rw-r--r-- | generic/tclAlloc.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/generic/tclAlloc.c b/generic/tclAlloc.c index df6db05..3d34113 100644 --- a/generic/tclAlloc.c +++ b/generic/tclAlloc.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclAlloc.c,v 1.24 2007/04/17 14:49:53 dkf Exp $ + * RCS: @(#) $Id: tclAlloc.c,v 1.24.2.1 2007/07/01 17:31:22 dgp Exp $ */ /* @@ -44,6 +44,16 @@ typedef unsigned long caddr_t; #endif /* + * Alignment for allocated memory. + */ + +#if defined(__APPLE__) +#define ALLOCALIGN 16 +#else +#define ALLOCALIGN 8 +#endif + +/* * The overhead on a block is at least 8 bytes. When free, this space contains * a pointer to the next free block, and the bottom two bits must be zero. * When in use, the first byte is set to MAGIC, and the second byte is the @@ -55,17 +65,17 @@ typedef unsigned long caddr_t; */ union overhead { - union overhead *next; /* when free */ - unsigned char padding[8]; /* Ensure the structure is 8-byte aligned. */ + union overhead *next; /* when free */ + unsigned char padding[ALLOCALIGN]; /* align struct to ALLOCALIGN bytes */ struct { - unsigned char magic0; /* magic number */ - unsigned char index; /* bucket # */ - unsigned char unused; /* unused */ - unsigned char magic1; /* other magic number */ + unsigned char magic0; /* magic number */ + unsigned char index; /* bucket # */ + unsigned char unused; /* unused */ + unsigned char magic1; /* other magic number */ #ifdef RCHECK - unsigned short rmagic; /* range magic number */ - unsigned long size; /* actual block size */ - unsigned short unused2; /* padding to 8-byte align */ + unsigned short rmagic; /* range magic number */ + unsigned long size; /* actual block size */ + unsigned short unused2; /* padding to 8-byte align */ #endif } ovu; #define overMagic0 ovu.magic0 @@ -96,11 +106,12 @@ union overhead { /* * nextf[i] is the pointer to the next free block of size 2^(i+3). The - * smallest allocatable block is 8 bytes. The overhead information precedes - * the data area returned to the user. + * smallest allocatable block is MINBLOCK bytes. The overhead information + * precedes the data area returned to the user. */ -#define NBUCKETS 13 +#define MINBLOCK ((sizeof(union overhead) + (ALLOCALIGN-1)) & ~(ALLOCALIGN-1)) +#define NBUCKETS (13 - (MINBLOCK >> 4)) #define MAXMALLOC (1<<(NBUCKETS+2)) static union overhead *nextf[NBUCKETS]; @@ -211,7 +222,7 @@ TclInitAlloc(void) void TclFinalizeAllocSubsystem(void) { - int i; + unsigned int i; struct block *blockPtr, *nextPtr; Tcl_MutexLock(allocMutexPtr); @@ -319,13 +330,8 @@ TclpAlloc( * for accounting. */ -#ifndef RCHECK - amount = 8; /* size of first bucket */ - bucket = 0; -#else - amount = 16; /* size of first bucket */ - bucket = 1; -#endif + amount = MINBLOCK; /* size of first bucket */ + bucket = MINBLOCK >> 4; while (numBytes + OVERHEAD > amount) { amount <<= 1; |