summaryrefslogtreecommitdiffstats
path: root/generic/tclAlloc.c
diff options
context:
space:
mode:
authordas <das>2007-06-29 03:17:32 (GMT)
committerdas <das>2007-06-29 03:17:32 (GMT)
commit18e1cd3cc3f1062987089b2d89e4950fdf892f37 (patch)
treeaf59dc494a087f7d1c0ec24eeecee20d05ebd834 /generic/tclAlloc.c
parent7c919ec8cb01aa1aa873b2988adeea684e33ccf1 (diff)
downloadtcl-18e1cd3cc3f1062987089b2d89e4950fdf892f37.zip
tcl-18e1cd3cc3f1062987089b2d89e4950fdf892f37.tar.gz
tcl-18e1cd3cc3f1062987089b2d89e4950fdf892f37.tar.bz2
* generic/tclAlloc.c: on Darwin, ensure memory allocated by
* generic/tclThreadAlloc.c: the custom TclpAlloc()s is aligned to 16 byte boundaries (as is the case with the Darwin system malloc).
Diffstat (limited to 'generic/tclAlloc.c')
-rw-r--r--generic/tclAlloc.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/generic/tclAlloc.c b/generic/tclAlloc.c
index e51ba8e..f3dfb35 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.16.2.1 2004/10/28 21:12:37 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclAlloc.c,v 1.16.2.2 2007/06/29 03:17:33 das Exp $
*/
/*
@@ -45,6 +45,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
@@ -56,8 +66,8 @@ typedef unsigned long caddr_t;
*/
union overhead {
- union overhead *ov_next; /* when free */
- unsigned char ov_padding[8]; /* Ensure the structure is 8-byte aligned. */
+ union overhead *ov_next; /* when free */
+ unsigned char ov_padding[ALLOCALIGN];/* align struct to ALLOCALIGN bytes */
struct {
unsigned char ovu_magic0; /* magic number */
unsigned char ovu_index; /* bucket # */
@@ -90,11 +100,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
+ * 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];
@@ -208,7 +219,7 @@ TclInitAlloc()
void
TclFinalizeAllocSubsystem()
{
- int i;
+ unsigned int i;
struct block *blockPtr, *nextPtr;
Tcl_MutexLock(allocMutexPtr);
@@ -310,13 +321,10 @@ TclpAlloc(nbytes)
* stored in hash buckets which satisfies request.
* Account for space used per block for accounting.
*/
-#ifndef RCHECK
- amt = 8; /* size of first bucket */
- bucket = 0;
-#else
- amt = 16; /* size of first bucket */
- bucket = 1;
-#endif
+
+ amount = MINBLOCK; /* size of first bucket */
+ bucket = MINBLOCK >> 4;
+
while (nbytes + OVERHEAD > amt) {
amt <<= 1;
if (amt == 0) {